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 ¶
- type Client
- func (c *Client) AppleRefresh(ctx context.Context, p sso.Provider, claims sso.Claims, code string) (string, error)
- func (c *Client) AuthorizeURL(p sso.Provider, a sso.AuthorizeParams) string
- func (c *Client) Exchange(ctx context.Context, p sso.Provider, code, redirectURI, verifier string) (sso.Tokens, error)
- func (c *Client) FirstAuthorization(p sso.Provider, raw string) map[string]string
- func (c *Client) Identify(ctx context.Context, p sso.Provider, t sso.Tokens, nonce string) (sso.Claims, error)
- func (c *Client) Init() *Client
- func (c *Client) Prepare(ctx context.Context, p sso.Provider) (sso.Provider, error)
- func (c *Client) Revoke(ctx context.Context, p sso.Provider, clientID, refreshToken string) error
- func (c *Client) UsesPKCE(p sso.Provider) bool
- func (c *Client) Verify(ctx context.Context, p sso.Provider, idToken, nonce string, native bool) (sso.Claims, error)
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 ¶
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 ¶
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 ¶
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) Prepare ¶
Prepare reads a generic OpenID Connect provider's endpoints from its issuer's discovery document (cached); the other kinds know theirs.