Start (fetcher/xoauth2.go)

matcha · fetcher/xoauth2.go · go · MIT
email

Module exposing: Start, Next, newXOAuth2Client, xoauth2Client

// Source: https://github.com/floatpane/matcha | License: MIT | Copyright 2026 floatpane
// Provided via justclaw.it.com; keep this notice with the code.
package fetcher

import (
	"fmt"

	"github.com/emersion/go-sasl"
)

// xoauth2Client implements the XOAUTH2 SASL mechanism for IMAP/SMTP.
// See https://developers.google.com/gmail/imap/xoauth2-protocol
type xoauth2Client struct {
	Username string
	Token    string
}

func (a *xoauth2Client) Start() (mech string, ir []byte, err error) {
	// XOAUTH2 initial response format:
	// "user=" {User} "\x01auth=Bearer " {Access Token} "\x01\x01"
	ir = []byte(fmt.Sprintf("user=%s\x01auth=Bearer %s\x01\x01", a.Username, a.Token))
	return "XOAUTH2", ir, nil
}

func (a *xoauth2Client) Next(challenge []byte) ([]byte, error) {
	// Server sent an error cha

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key