Documentation
¶
Overview ¶
Package mailauth is the OAuth client of the mail server: discovery, registration and tokens.
Index ¶
- Constants
- Variables
- func CheckIssuer(m *Meta, iss string) error
- func Config(m *Meta, r *Registration, redirectURL string) *oauth2.Config
- func IDTokenSubject(m *Meta, tok *oauth2.Token, cfg *oauth2.Config, nonce string) (string, error)
- func SameSite(a, b string) bool
- func Scopes(m *Meta) []string
- type BearerTransport
- type Env
- func (e *Env) Client(cfg *oauth2.Config, tok *oauth2.Token, sessionURL string, ...) *jmapc.Client
- func (e *Env) Context(ctx context.Context) context.Context
- func (e *Env) Discover(ctx context.Context, email string) (*Server, error)
- func (e *Env) DiscoverAuthServer(ctx context.Context, sessionURL string) (*Meta, error)
- func (e *Env) Register(ctx context.Context, m *Meta, name string, redirectURIs []string, ...) (*Registration, error)
- func (e *Env) StaticClient(ctx context.Context, server string, r *Registration) (*Meta, error)
- type Meta
- type Registration
- type Server
Constants ¶
const MailScope = "urn:ietf:params:oauth:scope:mail"
MailScope is the JMAP mail scope advertised by Stalwart and other JMAP servers.
Variables ¶
var ErrNoRegistration = errors.New("does not support dynamic client registration")
ErrNoRegistration means the authorization server has no registration endpoint (RFC 7591).
Functions ¶
func CheckIssuer ¶
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 ¶
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).
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.
type Env ¶
Env bundles the guarded HTTP client used for every request to mail servers.
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) Discover ¶
Discover finds the JMAP session and the authorization server for an email address.
func (*Env) DiscoverAuthServer ¶
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
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.