Documentation
¶
Index ¶
- Constants
- type Authenticator
- func (a *Authenticator) Exchange(ctx context.Context, code string) (*oauth2.Token, error)
- func (a *Authenticator) ExtractTokenFromRequest(r *http.Request) string
- func (a *Authenticator) GenerateState() (string, error)
- func (a *Authenticator) GetBaseURL() (string, error)
- func (a *Authenticator) GetClientID() string
- func (a *Authenticator) GetClientOrigin() string
- func (a *Authenticator) RevokeToken(ctx context.Context, token string) error
- func (a *Authenticator) VerifyAccessToken(ctx context.Context, token *oauth2.Token) (*oidc.IDToken, error)
- func (a *Authenticator) VerifyState(s string) error
- func (a *Authenticator) VerifyToken(ctx context.Context, token *oauth2.Token) (*oidc.IDToken, error)
- type Option
Constants ¶
const ( AuthHeader string = "Authorization" AuthHeaderPrefix string = "Bearer " )
Authorization headers constants.
const ( StateGenerationByteSize = 32 StatePartCount = 2 )
OAuth state token generation constants.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Authenticator ¶
type Authenticator struct {
Provider *oidc.Provider
Config oauth2.Config
HMACSecret []byte
APIAudience string
ClientOrigin string
// contains filtered or unexported fields
}
Authenticator encapsulates OAuth2 and OpenID Connect (OIDC) authentication functionality. It provides methods for user login, callback handling, token verification, and middleware for protecting routes that require authentication.
func (*Authenticator) ExtractTokenFromRequest ¶
func (a *Authenticator) ExtractTokenFromRequest(r *http.Request) string
ExtractTokenFromRequest gets the bearer token from the Authorization header.
func (*Authenticator) GenerateState ¶
func (a *Authenticator) GenerateState() (string, error)
GenerateState computes the state based on HMACSecret.
func (*Authenticator) GetBaseURL ¶
func (a *Authenticator) GetBaseURL() (string, error)
GetBaseURL returns the auth0 provider endpoint URL.
func (*Authenticator) GetClientID ¶
func (a *Authenticator) GetClientID() string
GetClientID returns the OAuth's clientID.
func (*Authenticator) GetClientOrigin ¶
func (a *Authenticator) GetClientOrigin() string
GetClientOrigin returns the client origin that will redirect by authenticator.
func (*Authenticator) RevokeToken ¶
func (a *Authenticator) RevokeToken(ctx context.Context, token string) error
RevokeToken sends a request to Auth0 to revoke the token.
func (*Authenticator) VerifyAccessToken ¶
func (a *Authenticator) VerifyAccessToken(ctx context.Context, token *oauth2.Token) (*oidc.IDToken, error)
VerifyAccessToken verifies an access token.
func (*Authenticator) VerifyState ¶
func (a *Authenticator) VerifyState(s string) error
VerifyState verifies if the state is matching with expected signature.
func (*Authenticator) VerifyToken ¶
func (a *Authenticator) VerifyToken(ctx context.Context, token *oauth2.Token) (*oidc.IDToken, error)
VerifyToken verifies the ID token and returns the parsed token.
type Option ¶
type Option func(*Authenticator)
Option defines a function type to apply options to Authenticator.
func WithAPIAudience ¶
WithAPIAudience sets the API audience for access token verification.
func WithClientOrigin ¶
WithClientOrigin sets the client origin for CORS configuration and redirection after the verification.
func WithHMACSecret ¶
WithHMACSecret sets the HMAC secret for state parameter verification.
func WithLogger ¶
WithLogger sets the logger for the authenticator.
func WithOAuthConfig ¶
WithOAuthConfig sets the OAuth2 configuration.