oauth2

package
v0.2.36 Latest Latest
Warning

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

Go to latest
Published: May 28, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ContextKeySkipStatelessIntrospection is utilzed to communicate skipping StatelessJWTValidator which is useful for
	// the UserInfo endpoint.
	ContextKeySkipStatelessIntrospection = contextKey(0)
)

Functions

func AccessTokenJWTToRequest

func AccessTokenJWTToRequest(token *jwt.Token) oauth2.Requester

AccessTokenJWTToRequest tries to reconstruct oauth2.Request from a JWT.

func SetSkipStatelessIntrospection added in v0.2.6

func SetSkipStatelessIntrospection(ctx context.Context) context.Context

SetSkipStatelessIntrospection sets the ContextKeySkipStatelessIntrospection to true.

Types

type AccessTokenStorage

type AccessTokenStorage interface {
	CreateAccessTokenSession(ctx context.Context, signature string, request oauth2.Requester) (err error)

	GetAccessTokenSession(ctx context.Context, signature string, session oauth2.Session) (request oauth2.Requester, err error)

	DeleteAccessTokenSession(ctx context.Context, signature string) (err error)
}

type AccessTokenStrategy

type AccessTokenStrategy interface {
	// IsOpaqueAccessToken returns true if the provided token is possibly an opaque Access Token.
	//
	// This function is only effective if the token provided has a deterministic characteristic such as a prefix.
	IsOpaqueAccessToken(ctx context.Context, token string) (is bool)

	// AccessTokenSignature returns the signature of the provided Access Token.
	AccessTokenSignature(ctx context.Context, token string) (signature string)

	// GenerateAccessToken generates a new Access Token.
	GenerateAccessToken(ctx context.Context, request oauth2.Requester) (token string, signature string, err error)

	// ValidateAccessToken validates the provided Access Token.
	ValidateAccessToken(ctx context.Context, request oauth2.Requester, token string) (err error)
}

type AuthorizeCodeStorage

type AuthorizeCodeStorage interface {
	// CreateAuthorizeCodeSession stores the authorization request for a given authorization code.
	CreateAuthorizeCodeSession(ctx context.Context, code string, request oauth2.Requester) (err error)

	// GetAuthorizeCodeSession hydrates the session based on the given code and returns the authorization request.
	// If the authorization code has been invalidated with `InvalidateAuthorizeCodeSession`, this
	// method should return the ErrInvalidatedAuthorizeCode error.
	//
	// Make sure to also return the oauth2.Requester value when returning the oauth2.ErrInvalidatedAuthorizeCode error!
	GetAuthorizeCodeSession(ctx context.Context, code string, session oauth2.Session) (request oauth2.Requester, err error)

	// InvalidateAuthorizeCodeSession is called when an authorize code is being used. The state of the authorization
	// code should be set to invalid and consecutive requests to GetAuthorizeCodeSession should return the
	// ErrInvalidatedAuthorizeCode error.
	InvalidateAuthorizeCodeSession(ctx context.Context, code string) (err error)
}

AuthorizeCodeStorage handles storage requests related to authorization codes.

type AuthorizeCodeStrategy

type AuthorizeCodeStrategy interface {
	// IsOpaqueAuthorizeCode returns true if the provided token is possibly an opaque Authorize Code.
	//
	// This function is only effective if the token provided has a deterministic characteristic such as a prefix.
	IsOpaqueAuthorizeCode(ctx context.Context, token string) bool

	// AuthorizeCodeSignature returns the signature of the provided Authorize Code.
	AuthorizeCodeSignature(ctx context.Context, token string) (signature string)

	// GenerateAuthorizeCode generates a new Authorize Code.
	GenerateAuthorizeCode(ctx context.Context, request oauth2.Requester) (token string, signature string, err error)

	// ValidateAuthorizeCode validates the provided Authorize Code.
	ValidateAuthorizeCode(ctx context.Context, request oauth2.Requester, token string) (err error)
}

type AuthorizeExplicitGrantHandler

AuthorizeExplicitGrantHandler is a response handler for the Authorize Code grant using the explicit grant type as defined in https://datatracker.ietf.org/doc/html/rfc6749#section-4.1

func (*AuthorizeExplicitGrantHandler) CanHandleTokenEndpointRequest

func (c *AuthorizeExplicitGrantHandler) CanHandleTokenEndpointRequest(ctx context.Context, request oauth2.AccessRequester) bool

func (*AuthorizeExplicitGrantHandler) CanSkipClientAuth

func (c *AuthorizeExplicitGrantHandler) CanSkipClientAuth(ctx context.Context, request oauth2.AccessRequester) bool

func (*AuthorizeExplicitGrantHandler) GetRedirectSecureChecker added in v0.1.19

func (c *AuthorizeExplicitGrantHandler) GetRedirectSecureChecker(ctx context.Context) (checker func(context.Context, *url.URL) bool)

func (*AuthorizeExplicitGrantHandler) GetSanitationWhiteList

func (c *AuthorizeExplicitGrantHandler) GetSanitationWhiteList(ctx context.Context) []string

func (*AuthorizeExplicitGrantHandler) HandleAuthorizeEndpointRequest

func (c *AuthorizeExplicitGrantHandler) HandleAuthorizeEndpointRequest(ctx context.Context, request oauth2.AuthorizeRequester, response oauth2.AuthorizeResponder) error

func (*AuthorizeExplicitGrantHandler) HandleTokenEndpointRequest

func (c *AuthorizeExplicitGrantHandler) HandleTokenEndpointRequest(ctx context.Context, request oauth2.AccessRequester) (err error)

HandleTokenEndpointRequest implements * https://datatracker.ietf.org/doc/html/rfc6749#section-4.1.3 (everything)

func (*AuthorizeExplicitGrantHandler) IssueAuthorizeCode

func (c *AuthorizeExplicitGrantHandler) IssueAuthorizeCode(ctx context.Context, request oauth2.AuthorizeRequester, response oauth2.AuthorizeResponder) (err error)

func (*AuthorizeExplicitGrantHandler) PopulateTokenEndpointResponse

func (c *AuthorizeExplicitGrantHandler) PopulateTokenEndpointResponse(ctx context.Context, request oauth2.AccessRequester, response oauth2.AccessResponder) (err error)

PopulateTokenEndpointResponse implements oauth2.TokenEndpointHandler.

TODO: Refactor time permitting.

type AuthorizeImplicitGrantTypeHandler

type AuthorizeImplicitGrantTypeHandler struct {
	AccessTokenStrategy AccessTokenStrategy
	// AccessTokenStorage is used to persist session data across requests.
	AccessTokenStorage AccessTokenStorage

	Config interface {
		oauth2.AccessTokenLifespanProvider
		oauth2.ScopeStrategyProvider
		oauth2.AudienceStrategyProvider
		oauth2.ResourceStrategyProvider
	}
}

AuthorizeImplicitGrantTypeHandler is a response handler for the Authorize Code grant using the implicit grant type as defined in https://datatracker.ietf.org/doc/html/rfc6749#section-4.2

func (*AuthorizeImplicitGrantTypeHandler) HandleAuthorizeEndpointRequest

func (c *AuthorizeImplicitGrantTypeHandler) HandleAuthorizeEndpointRequest(ctx context.Context, request oauth2.AuthorizeRequester, response oauth2.AuthorizeResponder) (err error)

func (*AuthorizeImplicitGrantTypeHandler) IssueImplicitAccessToken

func (c *AuthorizeImplicitGrantTypeHandler) IssueImplicitAccessToken(ctx context.Context, request oauth2.AuthorizeRequester, response oauth2.AuthorizeResponder) (err error)

type ClientCredentialsGrantHandler

func (*ClientCredentialsGrantHandler) CanHandleTokenEndpointRequest

func (c *ClientCredentialsGrantHandler) CanHandleTokenEndpointRequest(_ context.Context, request oauth2.AccessRequester) bool

func (*ClientCredentialsGrantHandler) CanSkipClientAuth

func (*ClientCredentialsGrantHandler) HandleTokenEndpointRequest

func (c *ClientCredentialsGrantHandler) HandleTokenEndpointRequest(ctx context.Context, request oauth2.AccessRequester) (err error)

HandleTokenEndpointRequest implements https://datatracker.ietf.org/doc/html/rfc6749#section-4.4.2

func (*ClientCredentialsGrantHandler) PopulateTokenEndpointResponse

func (c *ClientCredentialsGrantHandler) PopulateTokenEndpointResponse(ctx context.Context, request oauth2.AccessRequester, response oauth2.AccessResponder) (err error)

PopulateTokenEndpointResponse implements https://datatracker.ietf.org/doc/html/rfc6749#section-4.4.3

type ClientCredentialsGrantStorage

type ClientCredentialsGrantStorage interface {
	AccessTokenStorage
}

type CodeTokenEndpointHandler

type CodeTokenEndpointHandler interface {
	ValidateGrantTypes(ctx context.Context, request oauth2.AccessRequester) (err error)
	ValidateCodeAndSession(ctx context.Context, request oauth2.AccessRequester, authorizeRequest oauth2.Requester, code string) (err error)
	GetCodeAndSession(ctx context.Context, request oauth2.AccessRequester) (code string, signature string, r oauth2.Requester, err error)
	UpdateLastChecked(ctx context.Context, request oauth2.AccessRequester, authorizeRequest oauth2.Requester) (err error)
	InvalidateSession(ctx context.Context, signature string, request oauth2.Requester) error
	CanSkipClientAuth(ctx context.Context, request oauth2.AccessRequester) bool
	CanHandleTokenEndpointRequest(ctx context.Context, request oauth2.AccessRequester) bool
	DeviceCodeSignature(ctx context.Context, code string) (signature string, err error)
}

type CoreStrategy

CoreStrategy performs the major elements of token generation and validation.

func NewCoreStrategy

func NewCoreStrategy(config CoreStrategyConfigurator, prefix string, strategy jwt.Strategy) (core CoreStrategy)

NewCoreStrategy is a special constructor that if provided a signer will automatically decorate the HMACCoreStrategy with a JWTProfileCoreStrategy, otherwise it just returns the HMACCoreStrategy.

type CoreValidator

type CoreValidator struct {
	CoreStrategy
	CoreStorage
	Config coreValidatorConfigProvider
}

func (*CoreValidator) IntrospectToken

func (c *CoreValidator) IntrospectToken(ctx context.Context, token string, tokenUseHint oauth2.TokenUse, request oauth2.AccessRequester, scopes []string) (tokenUse oauth2.TokenUse, err error)

type DeviceCodeStrategy

type DeviceCodeStrategy interface {
	// IsOpaqueRFC8628DeviceCode returns true if the provided token is possibly an opaque RFC8628 Device Code.
	//
	// This function is only effective if the token provided has a deterministic characteristic such as a prefix.
	IsOpaqueRFC8628DeviceCode(ctx context.Context, token string) (is bool)

	// RFC8628DeviceCodeSignature returns the signature of the provided RFC8628 Device Code.
	RFC8628DeviceCodeSignature(ctx context.Context, code string) (signature string, err error)

	// GenerateRFC8628DeviceCode generates a new RFC8628 Device Code.
	GenerateRFC8628DeviceCode(ctx context.Context) (code string, signature string, err error)

	// ValidateRFC8628DeviceCode validates the provided RFC8628 Device Code.
	ValidateRFC8628DeviceCode(ctx context.Context, r oauth2.Requester, code string) (err error)
}

type GenericCodeTokenEndpointHandler

type GenericCodeTokenEndpointHandler struct {
	CodeTokenEndpointHandler

	AccessTokenStrategy    AccessTokenStrategy
	RefreshTokenStrategy   RefreshTokenStrategy
	CoreStorage            CoreStorage
	TokenRevocationStorage TokenRevocationStorage
	Config                 interface {
		oauth2.AccessTokenLifespanProvider
		oauth2.RefreshTokenLifespanProvider
		oauth2.RefreshTokenScopesProvider
	}
}

func (*GenericCodeTokenEndpointHandler) CanHandleTokenEndpointRequest

func (c *GenericCodeTokenEndpointHandler) CanHandleTokenEndpointRequest(ctx context.Context, request oauth2.AccessRequester) bool

func (*GenericCodeTokenEndpointHandler) CanSkipClientAuth

func (c *GenericCodeTokenEndpointHandler) CanSkipClientAuth(ctx context.Context, request oauth2.AccessRequester) bool

func (*GenericCodeTokenEndpointHandler) HandleTokenEndpointRequest

func (c *GenericCodeTokenEndpointHandler) HandleTokenEndpointRequest(ctx context.Context, request oauth2.AccessRequester) (err error)

HandleTokenEndpointRequest handles verifying the access request.

func (*GenericCodeTokenEndpointHandler) PopulateTokenEndpointResponse

func (c *GenericCodeTokenEndpointHandler) PopulateTokenEndpointResponse(ctx context.Context, request oauth2.AccessRequester, response oauth2.AccessResponder) (err error)

PopulateTokenEndpointResponse handles populating the access response.

type HMACCoreStrategy

type HMACCoreStrategy struct {
	Enigma *hmac.HMACStrategy
	Config interface {
		oauth2.AccessTokenLifespanProvider
		oauth2.RefreshTokenLifespanProvider
		oauth2.AuthorizeCodeLifespanProvider
		oauth2.RFC9628DeviceAuthorizeConfigProvider
	}
	// contains filtered or unexported fields
}

func NewHMACCoreStrategy

func NewHMACCoreStrategy(config HMACCoreStrategyConfigurator, prefix string) (strategy *HMACCoreStrategy)

NewHMACCoreStrategy creates a new HMACCoreStrategy with the potential to include the prefix format. The prefix must include a single '%s' for the purpose of adding the token part (ac, at, and rt; for the Authorize Code, Access Token, and Refresh Token; respectively.

func (*HMACCoreStrategy) AccessTokenSignature

func (s *HMACCoreStrategy) AccessTokenSignature(ctx context.Context, tokenString string) (signature string)

AccessTokenSignature implements oauth2.AccessTokenStrategy.

func (*HMACCoreStrategy) AuthorizeCodeSignature

func (s *HMACCoreStrategy) AuthorizeCodeSignature(ctx context.Context, tokenString string) (signature string)

AuthorizeCodeSignature implements oauth2.AuthorizeCodeStrategy.

func (*HMACCoreStrategy) GenerateAccessToken

func (s *HMACCoreStrategy) GenerateAccessToken(ctx context.Context, _ oauth2.Requester) (tokenString string, signature string, err error)

GenerateAccessToken implements oauth2.AccessTokenStrategy.

func (*HMACCoreStrategy) GenerateAuthorizeCode

func (s *HMACCoreStrategy) GenerateAuthorizeCode(ctx context.Context, _ oauth2.Requester) (tokenString string, signature string, err error)

GenerateAuthorizeCode implements oauth2.AuthorizeCodeStrategy.

func (*HMACCoreStrategy) GenerateRFC8628DeviceCode

func (s *HMACCoreStrategy) GenerateRFC8628DeviceCode(ctx context.Context) (tokenString string, signature string, err error)

GenerateRFC8628DeviceCode implements rfc8628.DeviceCodeStrategy.

func (*HMACCoreStrategy) GenerateRFC8628UserCode

func (s *HMACCoreStrategy) GenerateRFC8628UserCode(ctx context.Context) (tokenString string, signature string, err error)

GenerateRFC8628UserCode implements rfc8628.UserCodeStrategy.

func (*HMACCoreStrategy) GenerateRefreshToken

func (s *HMACCoreStrategy) GenerateRefreshToken(ctx context.Context, _ oauth2.Requester) (tokenString string, signature string, err error)

GenerateRefreshToken implements oauth2.RefreshTokenStrategy.

func (*HMACCoreStrategy) IsOpaqueAccessToken added in v0.2.6

func (s *HMACCoreStrategy) IsOpaqueAccessToken(ctx context.Context, tokenString string) bool

IsOpaqueAccessToken implements oauth2.AccessTokenStrategy.

func (*HMACCoreStrategy) IsOpaqueAuthorizeCode added in v0.2.6

func (s *HMACCoreStrategy) IsOpaqueAuthorizeCode(ctx context.Context, tokenString string) bool

IsOpaqueAuthorizeCode implements oauth2.AuthorizeCodeStrategy.

func (*HMACCoreStrategy) IsOpaqueRFC8628DeviceCode added in v0.2.6

func (s *HMACCoreStrategy) IsOpaqueRFC8628DeviceCode(ctx context.Context, tokenString string) bool

IsOpaqueRFC8628DeviceCode implements rfc8628.DeviceCodeStrategy.

func (*HMACCoreStrategy) IsOpaqueRefreshToken added in v0.2.6

func (s *HMACCoreStrategy) IsOpaqueRefreshToken(ctx context.Context, tokenString string) bool

IsOpaqueRefreshToken implements oauth2.RefreshTokenStrategy.

func (*HMACCoreStrategy) RFC8628DeviceCodeSignature

func (s *HMACCoreStrategy) RFC8628DeviceCodeSignature(ctx context.Context, tokenString string) (signature string, err error)

RFC8628DeviceCodeSignature implements rfc8628.DeviceCodeStrategy.

func (*HMACCoreStrategy) RFC8628UserCodeSignature

func (s *HMACCoreStrategy) RFC8628UserCodeSignature(ctx context.Context, tokenString string) (signature string, err error)

func (*HMACCoreStrategy) RefreshTokenSignature

func (s *HMACCoreStrategy) RefreshTokenSignature(ctx context.Context, tokenString string) (signature string)

RefreshTokenSignature implements oauth2.RefreshTokenStrategy.

func (*HMACCoreStrategy) ValidateAccessToken

func (s *HMACCoreStrategy) ValidateAccessToken(ctx context.Context, r oauth2.Requester, tokenString string) (err error)

ValidateAccessToken implements oauth2.AccessTokenStrategy.

func (*HMACCoreStrategy) ValidateAuthorizeCode

func (s *HMACCoreStrategy) ValidateAuthorizeCode(ctx context.Context, r oauth2.Requester, tokenString string) (err error)

ValidateAuthorizeCode implements oauth2.AuthorizeCodeStrategy.

func (*HMACCoreStrategy) ValidateRFC8628DeviceCode

func (s *HMACCoreStrategy) ValidateRFC8628DeviceCode(ctx context.Context, r oauth2.Requester, code string) (err error)

ValidateRFC8628DeviceCode implements rfc8628.DeviceCodeStrategy.

func (*HMACCoreStrategy) ValidateRFC8628UserCode

func (s *HMACCoreStrategy) ValidateRFC8628UserCode(ctx context.Context, r oauth2.Requester, code string) (err error)

ValidateRFC8628UserCode implements rfc8628.UserCodeStrategy.

func (*HMACCoreStrategy) ValidateRefreshToken

func (s *HMACCoreStrategy) ValidateRefreshToken(ctx context.Context, r oauth2.Requester, tokenString string) (err error)

ValidateRefreshToken implements oauth2.RefreshTokenStrategy.

type HandleHelper

type HandleHelper struct {
	AccessTokenStrategy AccessTokenStrategy
	AccessTokenStorage  AccessTokenStorage
	Config              HandleHelperConfigProvider
}

func (*HandleHelper) IssueAccessToken

func (h *HandleHelper) IssueAccessToken(ctx context.Context, defaultLifespan time.Duration, request oauth2.AccessRequester, response oauth2.AccessResponder) (err error)

type JWTProfileCoreStrategy

type JWTProfileCoreStrategy struct {
	jwt.Strategy

	HMACCoreStrategy *HMACCoreStrategy
	Config           interface {
		oauth2.AccessTokenIssuerProvider
		oauth2.JWTScopeFieldProvider
		oauth2.JWTProfileAccessTokensProvider
	}
}

JWTProfileCoreStrategy is a JWT RS256 strategy.

func (*JWTProfileCoreStrategy) AccessTokenSignature

func (s *JWTProfileCoreStrategy) AccessTokenSignature(ctx context.Context, tokenString string) (signature string)

func (*JWTProfileCoreStrategy) AuthorizeCodeSignature

func (s *JWTProfileCoreStrategy) AuthorizeCodeSignature(ctx context.Context, tokenString string) string

func (*JWTProfileCoreStrategy) GenerateAccessToken

func (s *JWTProfileCoreStrategy) GenerateAccessToken(ctx context.Context, request oauth2.Requester) (token string, signature string, err error)

func (*JWTProfileCoreStrategy) GenerateAuthorizeCode

func (s *JWTProfileCoreStrategy) GenerateAuthorizeCode(ctx context.Context, request oauth2.Requester) (tokenString string, signature string, err error)

func (*JWTProfileCoreStrategy) GenerateJWT

func (s *JWTProfileCoreStrategy) GenerateJWT(ctx context.Context, tokenType oauth2.TokenType, request oauth2.Requester, client oauth2.JWTProfileClient) (tokenString string, signature string, err error)

func (*JWTProfileCoreStrategy) GenerateRFC8628DeviceCode

func (s *JWTProfileCoreStrategy) GenerateRFC8628DeviceCode(ctx context.Context) (tokenString string, signature string, err error)

func (*JWTProfileCoreStrategy) GenerateRFC8628UserCode

func (s *JWTProfileCoreStrategy) GenerateRFC8628UserCode(ctx context.Context) (tokenString string, signature string, err error)

func (*JWTProfileCoreStrategy) GenerateRefreshToken

func (s *JWTProfileCoreStrategy) GenerateRefreshToken(ctx context.Context, request oauth2.Requester) (tokenString string, signature string, err error)

func (*JWTProfileCoreStrategy) IsOpaqueAccessToken added in v0.2.6

func (s *JWTProfileCoreStrategy) IsOpaqueAccessToken(ctx context.Context, tokenString string) bool

func (*JWTProfileCoreStrategy) IsOpaqueAuthorizeCode added in v0.2.6

func (s *JWTProfileCoreStrategy) IsOpaqueAuthorizeCode(ctx context.Context, tokenString string) bool

func (*JWTProfileCoreStrategy) IsOpaqueRFC8628DeviceCode added in v0.2.6

func (s *JWTProfileCoreStrategy) IsOpaqueRFC8628DeviceCode(ctx context.Context, tokenString string) bool

func (*JWTProfileCoreStrategy) IsOpaqueRefreshToken added in v0.2.6

func (s *JWTProfileCoreStrategy) IsOpaqueRefreshToken(ctx context.Context, tokenString string) bool

func (*JWTProfileCoreStrategy) IsPossiblyJWTProfileAccessToken

func (s *JWTProfileCoreStrategy) IsPossiblyJWTProfileAccessToken(ctx context.Context, tokenString string) (jwt bool, signature string)

func (*JWTProfileCoreStrategy) RFC8628DeviceCodeSignature

func (s *JWTProfileCoreStrategy) RFC8628DeviceCodeSignature(ctx context.Context, tokenString string) (signature string, err error)

func (*JWTProfileCoreStrategy) RFC8628UserCodeSignature

func (s *JWTProfileCoreStrategy) RFC8628UserCodeSignature(ctx context.Context, tokenString string) (signature string, err error)

func (*JWTProfileCoreStrategy) RefreshTokenSignature

func (s *JWTProfileCoreStrategy) RefreshTokenSignature(ctx context.Context, tokenString string) string

func (*JWTProfileCoreStrategy) ValidateAccessToken

func (s *JWTProfileCoreStrategy) ValidateAccessToken(ctx context.Context, request oauth2.Requester, tokenString string) (err error)

func (*JWTProfileCoreStrategy) ValidateAuthorizeCode

func (s *JWTProfileCoreStrategy) ValidateAuthorizeCode(ctx context.Context, request oauth2.Requester, tokenString string) error

func (*JWTProfileCoreStrategy) ValidateRFC8628DeviceCode

func (s *JWTProfileCoreStrategy) ValidateRFC8628DeviceCode(ctx context.Context, request oauth2.Requester, tokenString string) (err error)

func (*JWTProfileCoreStrategy) ValidateRFC8628UserCode

func (s *JWTProfileCoreStrategy) ValidateRFC8628UserCode(ctx context.Context, request oauth2.Requester, tokenString string) (err error)

func (*JWTProfileCoreStrategy) ValidateRefreshToken

func (s *JWTProfileCoreStrategy) ValidateRefreshToken(ctx context.Context, request oauth2.Requester, tokenString string) (err error)

type JWTSession

type JWTSession struct {
	JWTClaims *jwt.JWTClaims
	JWTHeader *jwt.Headers
	ExpiresAt map[oauth2.TokenType]time.Time
	Username  string
	Subject   string
}

JWTSession Container for the JWT session.

func (*JWTSession) Clone

func (j *JWTSession) Clone() oauth2.Session

func (*JWTSession) GetExpiresAt

func (j *JWTSession) GetExpiresAt(key oauth2.TokenType) time.Time

func (*JWTSession) GetExtraClaims

func (j *JWTSession) GetExtraClaims() map[string]any

GetExtraClaims implements ExtraClaimsSession for JWTSession. The returned value is a copy of JWTSession claims.

func (*JWTSession) GetJWTClaims

func (j *JWTSession) GetJWTClaims() jwt.JWTClaimsContainer

func (*JWTSession) GetJWTHeader

func (j *JWTSession) GetJWTHeader() *jwt.Headers

func (*JWTSession) GetSubject

func (j *JWTSession) GetSubject() string

func (*JWTSession) GetUsername

func (j *JWTSession) GetUsername() string

func (*JWTSession) SetExpiresAt

func (j *JWTSession) SetExpiresAt(key oauth2.TokenType, exp time.Time)

func (*JWTSession) SetSubject

func (j *JWTSession) SetSubject(subject string)

type JWTSessionContainer

type JWTSessionContainer interface {
	// GetJWTClaims returns the claims.
	GetJWTClaims() jwt.JWTClaimsContainer

	// GetJWTHeader returns the header.
	GetJWTHeader() *jwt.Headers

	oauth2.Session
}

type NoneResponseTypeHandler

NoneResponseTypeHandler is a response handler for when the None response type is requested as defined in https://openid.net/specs/oauth-v2-multiple-response-types-1_0.html#none

func (*NoneResponseTypeHandler) GetRedirectSecureChecker

func (c *NoneResponseTypeHandler) GetRedirectSecureChecker(ctx context.Context) func(context.Context, *url.URL) bool

func (*NoneResponseTypeHandler) HandleAuthorizeEndpointRequest

func (c *NoneResponseTypeHandler) HandleAuthorizeEndpointRequest(ctx context.Context, request oauth2.AuthorizeRequester, response oauth2.AuthorizeResponder) (err error)

type RefreshTokenGrantHandler

RefreshTokenGrantHandler handles access requests for the Refresh Token Flow.

func (*RefreshTokenGrantHandler) CanHandleTokenEndpointRequest

func (c *RefreshTokenGrantHandler) CanHandleTokenEndpointRequest(ctx context.Context, request oauth2.AccessRequester) bool

func (*RefreshTokenGrantHandler) CanSkipClientAuth

func (c *RefreshTokenGrantHandler) CanSkipClientAuth(ctx context.Context, request oauth2.AccessRequester) bool

func (*RefreshTokenGrantHandler) HandleTokenEndpointRequest

func (c *RefreshTokenGrantHandler) HandleTokenEndpointRequest(ctx context.Context, request oauth2.AccessRequester) (err error)

HandleTokenEndpointRequest implements https://datatracker.ietf.org/doc/html/rfc6749#section-6

TODO: Refactor time permitting.

func (*RefreshTokenGrantHandler) PopulateTokenEndpointResponse

func (c *RefreshTokenGrantHandler) PopulateTokenEndpointResponse(ctx context.Context, request oauth2.AccessRequester, response oauth2.AccessResponder) (err error)

PopulateTokenEndpointResponse implements https://datatracker.ietf.org/doc/html/rfc6749#section-6

type RefreshTokenStorage

type RefreshTokenStorage interface {
	CreateRefreshTokenSession(ctx context.Context, signature string, request oauth2.Requester) (err error)

	GetRefreshTokenSession(ctx context.Context, signature string, session oauth2.Session) (request oauth2.Requester, err error)

	DeleteRefreshTokenSession(ctx context.Context, signature string) (err error)
}

type RefreshTokenStrategy

type RefreshTokenStrategy interface {
	// IsOpaqueRefreshToken returns true if the provided token is possibly an opaque Refresh Token.
	//
	// This function is only effective if the token provided has a deterministic characteristic such as a prefix.
	IsOpaqueRefreshToken(ctx context.Context, token string) (is bool)

	// RefreshTokenSignature returns the signature of the provided Refresh Token.
	RefreshTokenSignature(ctx context.Context, token string) (signature string)

	// GenerateRefreshToken generates a new Refresh Token.
	GenerateRefreshToken(ctx context.Context, request oauth2.Requester) (token string, signature string, err error)

	// ValidateRefreshToken validates the provided Refresh Token.
	ValidateRefreshToken(ctx context.Context, request oauth2.Requester, token string) (err error)
}

type ResourceOwnerPasswordCredentialsGrantHandler deprecated

type ResourceOwnerPasswordCredentialsGrantHandler struct {
	*HandleHelper
	// ResourceOwnerPasswordCredentialsGrantStorage is used to persist session data across requests.
	ResourceOwnerPasswordCredentialsGrantStorage ResourceOwnerPasswordCredentialsGrantStorage
	RefreshTokenStrategy                         RefreshTokenStrategy
	Config                                       interface {
		oauth2.ScopeStrategyProvider
		oauth2.AudienceStrategyProvider
		oauth2.ResourceStrategyProvider
		oauth2.RefreshTokenScopesProvider
		oauth2.RefreshTokenLifespanProvider
		oauth2.AccessTokenLifespanProvider
	}
}

Deprecated: This handler is deprecated as a means to communicate that the ROPC grant type is widely discouraged and is at the time of this writing going to be omitted in the OAuth 2.1 spec. For more information on why this grant type is discouraged see: https://www.scottbrady91.com/oauth/why-the-resource-owner-password-credentials-grant-type-is-not-authentication-nor-suitable-for-modern-applications

func (*ResourceOwnerPasswordCredentialsGrantHandler) CanHandleTokenEndpointRequest

func (c *ResourceOwnerPasswordCredentialsGrantHandler) CanHandleTokenEndpointRequest(ctx context.Context, request oauth2.AccessRequester) bool

func (*ResourceOwnerPasswordCredentialsGrantHandler) CanSkipClientAuth

func (*ResourceOwnerPasswordCredentialsGrantHandler) HandleTokenEndpointRequest

func (c *ResourceOwnerPasswordCredentialsGrantHandler) HandleTokenEndpointRequest(ctx context.Context, request oauth2.AccessRequester) (err error)

HandleTokenEndpointRequest implements https://datatracker.ietf.org/doc/html/rfc6749#section-4.3.2

func (*ResourceOwnerPasswordCredentialsGrantHandler) PopulateTokenEndpointResponse

func (c *ResourceOwnerPasswordCredentialsGrantHandler) PopulateTokenEndpointResponse(ctx context.Context, request oauth2.AccessRequester, response oauth2.AccessResponder) error

PopulateTokenEndpointResponse implements https://datatracker.ietf.org/doc/html/rfc6749#section-4.3.3

type ResourceOwnerPasswordCredentialsGrantStorage

type ResourceOwnerPasswordCredentialsGrantStorage interface {
	Authenticate(ctx context.Context, name string, secret string) error
	AccessTokenStorage
	RefreshTokenStorage
}

type RevocationTokenLookupFunc

type RevocationTokenLookupFunc func(ctx context.Context, token string) (request oauth2.Requester, tokenType oauth2.TokenType, err error)

type StatelessJWTStrategy added in v0.2.6

type StatelessJWTStrategy interface {
	jwt.Strategy
	AccessTokenStrategy
	RefreshTokenStrategy
}

type StatelessJWTValidator

type StatelessJWTValidator struct {
	StatelessJWTStrategy
	Config interface {
		oauth2.ScopeStrategyProvider
	}
}

func (*StatelessJWTValidator) IntrospectToken

func (v *StatelessJWTValidator) IntrospectToken(ctx context.Context, tokenString string, tokenUse oauth2.TokenUse, request oauth2.AccessRequester, scopes []string) (use oauth2.TokenUse, err error)

type TokenRevocationHandler

type TokenRevocationHandler struct {
	TokenRevocationStorage TokenRevocationStorage
	RefreshTokenStrategy   RefreshTokenStrategy
	AccessTokenStrategy    AccessTokenStrategy
	Config                 interface {
		oauth2.RevokeRefreshTokensExplicitlyProvider
	}
}

func (*TokenRevocationHandler) RevokeToken

func (r *TokenRevocationHandler) RevokeToken(ctx context.Context, token string, tokenType oauth2.TokenType, client oauth2.Client) (err error)

RevokeToken implements https://datatracker.ietf.org/doc/html/rfc7009#section-2.1 The token type hint indicates which token type check should be performed first.

type TokenRevocationStorage

type TokenRevocationStorage interface {
	RefreshTokenStorage
	AccessTokenStorage

	// RevokeRefreshToken revokes a refresh token as specified in:
	// https://datatracker.ietf.org/doc/html/rfc7009#section-2.1
	// If the particular
	// token is a refresh token and the authorization server supports the
	// revocation of access tokens, then the authorization server SHOULD
	// also invalidate all access tokens based on the same authorization
	// grant (see Implementation Note).
	RevokeRefreshToken(ctx context.Context, requestID string) error

	// RevokeRefreshTokenMaybeGracePeriod revokes a refresh token as specified in:
	// https://datatracker.ietf.org/doc/html/rfc7009#section-2.1
	// If the particular
	// token is a refresh token and the authorization server supports the
	// revocation of access tokens, then the authorization server SHOULD
	// also invalidate all access tokens based on the same authorization
	// grant (see Implementation Note).
	//
	// If the Refresh Token grace period is greater than zero in configuration the token
	// will have its expiration time set as UTCNow + GracePeriod.
	RevokeRefreshTokenMaybeGracePeriod(ctx context.Context, requestID string, signature string) error

	// RevokeAccessToken revokes an access token as specified in:
	// https://datatracker.ietf.org/doc/html/rfc7009#section-2.1
	// If the token passed to the request
	// is an access token, the server MAY revoke the respective refresh
	// token as well.
	RevokeAccessToken(ctx context.Context, requestID string) error
}

TokenRevocationStorage provides the storage implementation as specified in: https://datatracker.ietf.org/doc/html/rfc7009

type UserCodeStrategy

type UserCodeStrategy interface {
	// RFC8628UserCodeSignature returns the signature of the provided RFC8628 User Code.
	RFC8628UserCodeSignature(ctx context.Context, code string) (signature string, err error)

	// GenerateRFC8628UserCode generates a new RFC8628 User Code.
	GenerateRFC8628UserCode(ctx context.Context) (code string, signature string, err error)

	// ValidateRFC8628UserCode validates the provided RFC8628 User Code.
	ValidateRFC8628UserCode(ctx context.Context, r oauth2.Requester, code string) (err error)
}

Jump to

Keyboard shortcuts

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