Documentation
¶
Overview ¶
Package oauth runs the provider side of signing in with Google and GitHub: building the authorization URL with PKCE and state, and swapping the returned code for the user's identity.
It holds no state of its own. The caller stores state, the PKCE verifier, and the nonce between the two steps, and decides what the identity means.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Apple ¶
type Apple struct {
// contains filtered or unexported fields
}
Apple checks the identity tokens of native Sign in with Apple on iOS. There's no redirect or code exchange: the app gets the signed token from the system sheet and sends it to the API.
func NewApple ¶
func NewApple(bundleIDs []string, e AppleEndpoints, now func() time.Time) *Apple
NewApple returns a checker for tokens issued to any of bundleIDs. now is the clock for the token's expiry check.
type AppleEndpoints ¶
AppleEndpoints are where Apple's keys live, and the issuer its tokens name. Tests point them at a fake.
func DefaultAppleEndpoints ¶
func DefaultAppleEndpoints() AppleEndpoints
DefaultAppleEndpoints returns Apple's real endpoints.
type GitHubEndpoints ¶
GitHubEndpoints are where GitHub's endpoints live. Tests point them at a fake.
func DefaultGitHubEndpoints ¶
func DefaultGitHubEndpoints() GitHubEndpoints
DefaultGitHubEndpoints returns GitHub's real endpoints.
type GoogleEndpoints ¶
type GoogleEndpoints struct {
AuthURL string
TokenURL string
JWKSURL string
// Issuers are the accepted values of the ID token's iss claim.
Issuers []string
}
GoogleEndpoints are where Google's endpoints live. Tests point them at a fake.
func DefaultGoogleEndpoints ¶
func DefaultGoogleEndpoints() GoogleEndpoints
DefaultGoogleEndpoints returns Google's real endpoints.
type Identity ¶
type Identity struct {
// Subject is the provider's ID for the user, which never changes.
Subject string
// Email is the user's address at the provider. It may be empty.
Email string
// EmailVerified reports whether the provider vouches for Email.
EmailVerified bool
}
Identity is who a provider says the user is.
type Provider ¶
type Provider interface {
// AuthCodeURL returns the URL to send the user to. verifier is the PKCE
// verifier; nonce is checked in the ID token, by providers that issue
// one.
AuthCodeURL(state, verifier, nonce, redirectURI string) string
// Exchange swaps the code from the provider's redirect for the user's
// identity.
Exchange(ctx context.Context, code, verifier, nonce, redirectURI string) (Identity, error)
}
Provider is one sign-in provider.
func NewGitHub ¶
func NewGitHub(clientID, clientSecret string, e GitHubEndpoints) Provider
NewGitHub returns GitHub sign-in. GitHub has no ID tokens, so the identity comes from its API: the user's ID, and their primary email if verified.