protocol

package
v0.9.15 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: MIT Imports: 10 Imported by: ? 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 protocol implements sso.Protocol over the oidc, oauth2 and apple packages: it is what the engine uses to speak to the real providers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// HTTP reaches the providers: safehttp.NewClient(…) in production.
	HTTP *http.Client
	// Now is the clock; time.Now when nil.
	Now func() time.Time
	// Dev allows http issuers (BACKD_DEV).
	Dev bool
	// contains filtered or unexported fields
}

Client speaks to identity providers. The zero value needs HTTP set.

func New

func New(dev bool) *Client

New is the client for the built-in providers: it dials only their hosts (private addresses too when dev).

func (*Client) AppleRefresh

func (c *Client) AppleRefresh(ctx context.Context, p sso.Provider, claims sso.Claims, code string) (string, error)

AppleRefresh trades the authorization code a native app sends with its ID token for Apple's refresh token. The code must belong to the same person and app as the token, or a client could make backd keep (and later revoke) someone else's token.

func (*Client) AuthorizeURL

func (c *Client) AuthorizeURL(p sso.Provider, a sso.AuthorizeParams) string

AuthorizeURL is where to send the person to sign in with the provider.

func (*Client) Exchange

func (c *Client) Exchange(ctx context.Context, p sso.Provider, code, redirectURI, verifier string) (sso.Tokens, error)

Exchange trades the authorization code for the person's tokens.

func (*Client) FirstAuthorization

func (c *Client) FirstAuthorization(p sso.Provider, raw string) map[string]string

FirstAuthorization reads the "user" field Apple posts to the callback the first time a person authorizes the app: {"name": {"firstName": …, "lastName": …}}. No other provider sends such a field, and one sent to them is ignored.

func (*Client) Identify

func (c *Client) Identify(ctx context.Context, p sso.Provider, t sso.Tokens, nonce string) (sso.Claims, error)

Identify says who the tokens of a code exchange are for: an OpenID Connect provider's ID token is verified, and the person of an OAuth 2 provider (GitHub, a plain service) is read with the access token, once.

func (*Client) Init

func (c *Client) Init() *Client

Init prepares a Client built from a struct literal and returns it.

func (*Client) Prepare

func (c *Client) Prepare(ctx context.Context, p sso.Provider) (sso.Provider, error)

Prepare reads a generic OpenID Connect provider's endpoints from its issuer's discovery document (cached); the other kinds know theirs.

func (*Client) Revoke

func (c *Client) Revoke(ctx context.Context, p sso.Provider, clientID, refreshToken string) error

Revoke tells Apple to revoke a refresh token.

func (*Client) UsesPKCE

func (c *Client) UsesPKCE(p sso.Provider) bool

UsesPKCE says whether a PKCE challenge goes to the provider.

func (*Client) Verify

func (c *Client) Verify(ctx context.Context, p sso.Provider, idToken, nonce string, native bool) (sso.Claims, error)

Verify checks an ID token and returns what it says.

Jump to

Keyboard shortcuts

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