Documentation
¶
Index ¶
- func ClearProviders()
- func NewOIDCProvider[T Claims](opts *OIDCOptions) (*oidcProvider[T], error)
- func NewProvider[T Claims](opts *ProviderOptions) (*provider[T], error)
- func RemoveProvider(name string)
- func UseProviders(p ...Provider)
- func WithForcedApprovalPrompt() oauth2.AuthCodeOption
- func WithHostedDomain(hd string) oauth2.AuthCodeOption
- func WithIdentityProvider(idp string) oauth2.AuthCodeOption
- func WithLoginHint(loginHint string) oauth2.AuthCodeOption
- func WithNonce(nonce string) oauth2.AuthCodeOption
- func WithOfflineAccess() oauth2.AuthCodeOption
- func WithOnlineAccess() oauth2.AuthCodeOption
- func WithPrompt(prompt ...string) oauth2.AuthCodeOption
- func WithScopes(scopes ...string) oauth2.AuthCodeOption
- type Address
- type AuthCode
- type Claims
- type OIDCOptions
- type Options
- type ParseIDTokenOptions
- type Provider
- type ProviderOptions
- type Providers
- type Token
- type User
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ClearProviders ¶
func ClearProviders()
ClearProviders removes all registered providers from the global providers map.
func NewOIDCProvider ¶
func NewOIDCProvider[T Claims](opts *OIDCOptions) (*oidcProvider[T], error)
newOIDCProvider creates a new provider for the given issuer and options.
This function wraps the go-oidc NewProvider function and the newProvider function in this package. It takes an OIDCOptions struct and returns an oidcProvider, which is a Provider that wraps an *oidc.Provider and can be used to authenticate users.
The returned Provider will have the given name, scopes, and auth options. The EndPoint field of the Provider's ProviderOptions will be set to the Provider's Endpoint().
func NewProvider ¶
func NewProvider[T Claims](opts *ProviderOptions) (*provider[T], error)
func RemoveProvider ¶
func RemoveProvider(name string)
func UseProviders ¶
func UseProviders(p ...Provider)
UseProviders sets the providers that can be used to authenticate with the server. If a provider with the same name already exists, it will be overwritten.
func WithForcedApprovalPrompt ¶
func WithForcedApprovalPrompt() oauth2.AuthCodeOption
WithForcedApprovalPrompt returns an AuthCodeOption that forces the user to approve the request every time, even if they previously approved a request with the same client_id and scope.
func WithHostedDomain ¶
func WithHostedDomain(hd string) oauth2.AuthCodeOption
WithHostedDomain returns an AuthCodeOption that adds the "hd" parameter to the authorize URL. The value of the parameter is the given domain.
See https://developers.google.com/identity/protocols/OpenIDConnect#hd-param
func WithIdentityProvider ¶
func WithIdentityProvider(idp string) oauth2.AuthCodeOption
WithIdentityProvider returns an AuthCodeOption that adds the "identity_provider" parameter to the authorize URL, which can be used to specify the identity provider that the user should use to authenticate.
See https://developers.google.com/identity/protocols/OpenIDConnect#hd-param
func WithLoginHint ¶
func WithLoginHint(loginHint string) oauth2.AuthCodeOption
WithLoginHint returns an AuthCodeOption that adds the "login_hint" parameter to the authorize URL. The value of the parameter is the given login hint.
See https://developers.google.com/identity/protocols/OpenIDConnect#login_hint
func WithNonce ¶
func WithNonce(nonce string) oauth2.AuthCodeOption
WithNonce returns an AuthCodeOption that adds the "nonce" parameter to the authorize URL. The value of the parameter is the given nonce.
See https://developers.google.com/identity/protocols/OpenIDConnect#nonce
func WithOfflineAccess ¶
func WithOfflineAccess() oauth2.AuthCodeOption
WithOfflineAccess returns an AuthCodeOption that requests a refresh token that can be used to obtain a new access token when the user is not present.
See https://developers.google.com/identity/protocols/OpenIDConnect#offline
func WithOnlineAccess ¶
func WithOnlineAccess() oauth2.AuthCodeOption
func WithPrompt ¶
func WithPrompt(prompt ...string) oauth2.AuthCodeOption
WithPrompt returns an AuthCodeOption that adds the "prompt" parameter to the authorize URL. The value of the parameter is the space-separated list of given prompts.
See https://developers.google.com/identity/protocols/OpenIDConnect#promptrelatedparameters
func WithScopes ¶
func WithScopes(scopes ...string) oauth2.AuthCodeOption
WithScopes returns an AuthCodeOption that adds the "scope" parameter to the authorize URL. The value of the parameter is the space-separated list of given scopes.
See https://developers.google.com/identity/protocols/OpenIDConnect#scopes
Types ¶
type OIDCOptions ¶
type ParseIDTokenOptions ¶
type Provider ¶
type Provider interface {
Name() string
AuthCodeURL(state string, opts ...oauth2.AuthCodeOption) *AuthCode
GetOAuthToken(code string, opts ...oauth2.AuthCodeOption) (*Token, error)
GetUserData(ctx context.Context, token *Token) (*User, error)
IsTokenValid(ctx context.Context, token *Token) bool
}
func GetProvider ¶
GetProvider returns the provider with the given name. If no provider with the given name exists, it returns an error.
type ProviderOptions ¶
type Providers ¶
func GetProviders ¶
func GetProviders() Providers
GetProviders returns a map of all providers that have been registered. The map is keyed by the name of the provider.
type User ¶
type User struct {
ID string `json:"sub,omitempty"`
Issuer string `json:"iss,omitempty"`
Name string `json:"name,omitempty"`
Email string `json:"email,omitempty"`
EmailVerified bool `json:"email_verified,omitempty"`
FirstName string `json:"given_name,omitempty"`
LastName string `json:"family_name,omitempty"`
MiddleName string `json:"middle_name,omitempty"`
Nickname string `json:"nickname,omitempty"`
UserName string `json:"preferred_username,omitempty"`
Gender string `json:"gender,omitempty"`
Birthdate string `json:"birthdate,omitempty"`
Profile string `json:"profile,omitempty"`
Picture string `json:"picture,omitempty"`
Zoneinfo string `json:"zoneinfo,omitempty"`
Locale string `json:"locale,omitempty"`
UpdatedAt int64 `json:"updated_at,omitempty"`
WebSite string `json:"website,omitempty"`
Phone string `json:"phone_number,omitempty"`
Address Address `json:"address"`
}