mailauth

package
v0.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 24, 2026 License: Apache-2.0 Imports: 18 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package mailauth is the OAuth client of the mail server: discovery, registration and tokens.

Index

Constants

View Source
const MailScope = "urn:ietf:params:oauth:scope:mail"

MailScope is the JMAP mail scope advertised by Stalwart and other JMAP servers.

Variables

View Source
var ErrNoRegistration = errors.New("does not support dynamic client registration")

ErrNoRegistration means the authorization server has no registration endpoint (RFC 7591).

Functions

func CheckIssuer

func CheckIssuer(m *Meta, iss string) error

CheckIssuer validates the RFC 9207 iss parameter of an authorization response.

func Config

func Config(m *Meta, r *Registration, redirectURL string) *oauth2.Config

Config builds the oauth2 configuration for a registration.

func IDTokenSubject

func IDTokenSubject(m *Meta, tok *oauth2.Token, cfg *oauth2.Config, nonce string) (string, error)

IDTokenSubject verifies the ID token returned with tok (nonce, issuer, audience) and returns its subject. An ID token is required when openid was requested. The token comes straight from the token endpoint over TLS, which authenticates it (OpenID Connect Core §3.1.3.7).

func SameSite

func SameSite(a, b string) bool

SameSite reports whether two host names share their registrable domain (eTLD+1). A JMAP host may only send its users to an authorization server of the same domain, otherwise it could collect the tokens another server issues.

func Scopes

func Scopes(m *Meta) []string

Scopes returns the scopes to request: openid, email, the JMAP mail scope and offline_access when advertised.

Types

type BearerTransport

type BearerTransport struct {
	Source oauth2.TokenSource
	Base   http.RoundTripper
}

BearerTransport adds the token to requests, except after a redirect to another host, unlike oauth2.Transport which would hand the token to whatever host a server redirects to.

func (*BearerTransport) RoundTrip

func (t *BearerTransport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip implements http.RoundTripper.

type Env

type Env struct {
	HTTP     *http.Client
	Net      netguard.Options
	Resolver jmapc.Resolver
}

Env bundles the guarded HTTP client used for every request to mail servers.

func NewEnv

func NewEnv(n netguard.Options) *Env

NewEnv returns an Env enforcing the network policy.

func (*Env) Client

func (e *Env) Client(cfg *oauth2.Config, tok *oauth2.Token, sessionURL string, save func(*oauth2.Token)) *jmapc.Client

Client returns a JMAP client whose token refreshes transparently; save is called with every new token.

func (*Env) Context

func (e *Env) Context(ctx context.Context) context.Context

Context carries the guarded HTTP client for golang.org/x/oauth2.

func (*Env) Discover

func (e *Env) Discover(ctx context.Context, email string) (*Server, error)

Discover finds the JMAP session and the authorization server for an email address.

func (*Env) DiscoverAuthServer

func (e *Env) DiscoverAuthServer(ctx context.Context, sessionURL string) (*Meta, error)

DiscoverAuthServer finds the authorization server protecting a session URL: RFC 9728 resource metadata first, then RFC 8414 and OpenID discovery on the same origin.

func (*Env) Register

func (e *Env) Register(ctx context.Context, m *Meta, name string, redirectURIs []string, confidential bool) (*Registration, error)

Register registers a client dynamically (RFC 7591). A confidential registration falls back to a public PKCE client when the server only allows anonymous public clients.

func (*Env) StaticClient added in v0.3.0

func (e *Env) StaticClient(ctx context.Context, server string, r *Registration) (*Meta, error)

StaticClient validates a client declared by the operator for server (an email address or a JMAP session URL) and returns the metadata of its authorization server.

type Meta

type Meta struct {
	oauthex.AuthServerMeta
	DeviceAuthorizationEndpoint string `json:"device_authorization_endpoint,omitempty"`
}

Meta is RFC 8414 metadata plus the device endpoint (RFC 8628).

type Registration

type Registration struct {
	ClientID     string   `json:"client_id"`
	ClientSecret string   `json:"client_secret,omitempty"`
	AuthMethod   string   `json:"auth_method"`
	RedirectURIs []string `json:"redirect_uris"`
	Static       bool     `json:"static,omitempty"`
}

Registration is this program's client registration at one authorization server.

type Server

type Server struct {
	SessionURL string
	Meta       *Meta
}

Server is a discovered mail server.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL