oauth2

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const RFC9068JWTType = "at+jwt"

RFC9068JWTType is the media type used to identify RFC 9068 access tokens in the JWT typ header

Variables

This section is empty.

Functions

func AccessTokenJWTToRequest

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

AccessTokenJWTToRequest tries to reconstruct fosite.Request from a JWT.

Types

type AccessTokenStorage

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

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

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

type AccessTokenStorageProvider

type AccessTokenStorageProvider interface {
	AccessTokenStorage() AccessTokenStorage
}

type AccessTokenStrategy

type AccessTokenStrategy interface {
	AccessTokenSignature(ctx context.Context, token string) string
	GenerateAccessToken(ctx context.Context, requester fosite.Requester) (token string, signature string, err error)
	ValidateAccessToken(ctx context.Context, requester fosite.Requester, token string) (err error)
}

type AccessTokenStrategyProvider

type AccessTokenStrategyProvider interface {
	AccessTokenStrategy() AccessTokenStrategy
}

type AuthorizeCodeStorage

type AuthorizeCodeStorage interface {
	// CreateAuthorizeCodeSession stores the authorization request keyed by signature.
	CreateAuthorizeCodeSession(ctx context.Context, signature string, request fosite.Requester) (err error)

	// GetAuthorizeCodeSession hydrates the session for an authorization code and returns
	// the authorization request. code is the original opaque code string from the client;
	// signature is the strategy-derived lookup key. Implementations that key sessions in a
	// database use signature; implementations that decode session state from the code
	// itself (e.g., AEAD-encoded codes) use code.
	//
	// If the authorization code has been invalidated with `InvalidateAuthorizeCodeSession`, this
	// method should return the ErrInvalidatedAuthorizeCode error.
	//
	// Make sure to also return the fosite.Requester value when returning the fosite.ErrInvalidatedAuthorizeCode error!
	GetAuthorizeCodeSession(ctx context.Context, code, signature string, session fosite.Session) (request fosite.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.
	//
	// code is the original opaque code; signature is the lookup key. Implementations that
	// record redemption state derived from the code's contents (e.g., a replay-marker row
	// whose fields come from the AEAD payload) use code; implementations that mutate a row
	// by PK use signature.
	InvalidateAuthorizeCodeSession(ctx context.Context, code, signature string) (err error)
}

AuthorizeCodeStorage handles storage requests related to authorization codes.

The /token-side methods receive both the original opaque authorization code and its strategy-derived signature. The default SQL persister keys rows by signature.

type AuthorizeCodeStorageProvider

type AuthorizeCodeStorageProvider interface {
	AuthorizeCodeStorage() AuthorizeCodeStorage
}

type AuthorizeCodeStrategy

type AuthorizeCodeStrategy interface {
	AuthorizeCodeSignature(ctx context.Context, token string) string
	GenerateAuthorizeCode(ctx context.Context, requester fosite.Requester) (token string, signature string, err error)
	ValidateAuthorizeCode(ctx context.Context, requester fosite.Requester, token string) (err error)
}

type AuthorizeCodeStrategyProvider

type AuthorizeCodeStrategyProvider interface {
	AuthorizeCodeStrategy() AuthorizeCodeStrategy
}

type AuthorizeExplicitGrantHandler

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

func (*AuthorizeExplicitGrantHandler) CanHandleTokenEndpointRequest

func (c *AuthorizeExplicitGrantHandler) CanHandleTokenEndpointRequest(_ context.Context, requester fosite.AccessRequester) bool

func (*AuthorizeExplicitGrantHandler) CanSkipClientAuth

func (*AuthorizeExplicitGrantHandler) GetSanitationWhiteList

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

func (*AuthorizeExplicitGrantHandler) HandleAuthorizeEndpointRequest

func (c *AuthorizeExplicitGrantHandler) HandleAuthorizeEndpointRequest(ctx context.Context, ar fosite.AuthorizeRequester, resp fosite.AuthorizeResponder) error

func (*AuthorizeExplicitGrantHandler) HandleTokenEndpointRequest

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

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

func (*AuthorizeExplicitGrantHandler) IssueAuthorizeCode

func (*AuthorizeExplicitGrantHandler) PopulateTokenEndpointResponse

func (c *AuthorizeExplicitGrantHandler) PopulateTokenEndpointResponse(ctx context.Context, requester fosite.AccessRequester, responder fosite.AccessResponder) (err error)

type AuthorizeImplicitGrantHandler

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

func (*AuthorizeImplicitGrantHandler) HandleAuthorizeEndpointRequest

func (c *AuthorizeImplicitGrantHandler) HandleAuthorizeEndpointRequest(ctx context.Context, ar fosite.AuthorizeRequester, resp fosite.AuthorizeResponder) error

func (*AuthorizeImplicitGrantHandler) IssueImplicitAccessToken

type ClientCredentialsGrantHandler

func (*ClientCredentialsGrantHandler) CanHandleTokenEndpointRequest

func (c *ClientCredentialsGrantHandler) CanHandleTokenEndpointRequest(ctx context.Context, requester fosite.AccessRequester) bool

func (*ClientCredentialsGrantHandler) CanSkipClientAuth

func (c *ClientCredentialsGrantHandler) CanSkipClientAuth(ctx context.Context, requester fosite.AccessRequester) bool

func (*ClientCredentialsGrantHandler) HandleTokenEndpointRequest

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

IntrospectTokenEndpointRequest implements https://tools.ietf.org/html/rfc6749#section-4.4.2

func (*ClientCredentialsGrantHandler) IssueAccessToken

func (c *ClientCredentialsGrantHandler) IssueAccessToken(ctx context.Context, atLifespan time.Duration, requester fosite.AccessRequester, responder fosite.AccessResponder) (signature string, err error)

func (*ClientCredentialsGrantHandler) PopulateTokenEndpointResponse

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

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

type CoreValidator

func (*CoreValidator) IntrospectToken

func (c *CoreValidator) IntrospectToken(ctx context.Context, token string, tokenUse fosite.TokenUse, accessRequest fosite.AccessRequester, scopes []string) (fosite.TokenUse, error)

type DefaultJWTStrategy

type DefaultJWTStrategy struct {
	Signer jwt.Signer
	Config interface {
		fosite.AccessTokenIssuerProvider
		fosite.JWTScopeFieldProvider
	}
}

DefaultJWTStrategy is a JWT RS256 strategy.

func (*DefaultJWTStrategy) AccessTokenSignature

func (h *DefaultJWTStrategy) AccessTokenSignature(_ context.Context, token string) string

func (*DefaultJWTStrategy) GenerateAccessToken

func (h *DefaultJWTStrategy) GenerateAccessToken(ctx context.Context, requester fosite.Requester) (token string, signature string, err error)

func (*DefaultJWTStrategy) ValidateAccessToken

func (h *DefaultJWTStrategy) ValidateAccessToken(ctx context.Context, _ fosite.Requester, token string) error

type HMACSHAStrategy

type HMACSHAStrategy struct {
	*HMACSHAStrategyUnPrefixed
}

func NewHMACSHAStrategy

func NewHMACSHAStrategy(
	enigma *enigma.HMACStrategy,
	config LifespanConfigProvider,
) *HMACSHAStrategy

func (*HMACSHAStrategy) GenerateAccessToken

func (h *HMACSHAStrategy) GenerateAccessToken(ctx context.Context, r fosite.Requester) (token string, signature string, err error)

func (*HMACSHAStrategy) GenerateAuthorizeCode

func (h *HMACSHAStrategy) GenerateAuthorizeCode(ctx context.Context, r fosite.Requester) (token string, signature string, err error)

func (*HMACSHAStrategy) GenerateRefreshToken

func (h *HMACSHAStrategy) GenerateRefreshToken(ctx context.Context, r fosite.Requester) (token string, signature string, err error)

func (*HMACSHAStrategy) ValidateAccessToken

func (h *HMACSHAStrategy) ValidateAccessToken(ctx context.Context, r fosite.Requester, token string) (err error)

func (*HMACSHAStrategy) ValidateAuthorizeCode

func (h *HMACSHAStrategy) ValidateAuthorizeCode(ctx context.Context, r fosite.Requester, token string) (err error)

func (*HMACSHAStrategy) ValidateRefreshToken

func (h *HMACSHAStrategy) ValidateRefreshToken(ctx context.Context, r fosite.Requester, token string) (err error)

type HMACSHAStrategyUnPrefixed

type HMACSHAStrategyUnPrefixed struct {
	Enigma *enigma.HMACStrategy
	Config LifespanConfigProvider
}

func NewHMACSHAStrategyUnPrefixed

func NewHMACSHAStrategyUnPrefixed(
	enigma *enigma.HMACStrategy,
	config LifespanConfigProvider,
) *HMACSHAStrategyUnPrefixed

func (*HMACSHAStrategyUnPrefixed) AccessTokenSignature

func (h *HMACSHAStrategyUnPrefixed) AccessTokenSignature(ctx context.Context, token string) string

func (*HMACSHAStrategyUnPrefixed) AuthorizeCodeSignature

func (h *HMACSHAStrategyUnPrefixed) AuthorizeCodeSignature(ctx context.Context, token string) string

func (*HMACSHAStrategyUnPrefixed) GenerateAccessToken

func (h *HMACSHAStrategyUnPrefixed) GenerateAccessToken(ctx context.Context, _ fosite.Requester) (token string, signature string, err error)

func (*HMACSHAStrategyUnPrefixed) GenerateAuthorizeCode

func (h *HMACSHAStrategyUnPrefixed) GenerateAuthorizeCode(ctx context.Context, _ fosite.Requester) (token string, signature string, err error)

func (*HMACSHAStrategyUnPrefixed) GenerateRefreshToken

func (h *HMACSHAStrategyUnPrefixed) GenerateRefreshToken(ctx context.Context, _ fosite.Requester) (token string, signature string, err error)

func (*HMACSHAStrategyUnPrefixed) RefreshTokenSignature

func (h *HMACSHAStrategyUnPrefixed) RefreshTokenSignature(ctx context.Context, token string) string

func (*HMACSHAStrategyUnPrefixed) ValidateAccessToken

func (h *HMACSHAStrategyUnPrefixed) ValidateAccessToken(ctx context.Context, r fosite.Requester, token string) (err error)

func (*HMACSHAStrategyUnPrefixed) ValidateAuthorizeCode

func (h *HMACSHAStrategyUnPrefixed) ValidateAuthorizeCode(ctx context.Context, r fosite.Requester, token string) (err error)

func (*HMACSHAStrategyUnPrefixed) ValidateRefreshToken

func (h *HMACSHAStrategyUnPrefixed) ValidateRefreshToken(ctx context.Context, r fosite.Requester, token string) (err error)

type HandleHelper

type HandleHelper struct {
	AccessTokenStrategy AccessTokenStrategy
	Storage             AccessTokenStorageProvider
	Config              HandleHelperConfigProvider
}

func (*HandleHelper) IssueAccessToken

func (h *HandleHelper) IssueAccessToken(ctx context.Context, defaultLifespan time.Duration, requester fosite.AccessRequester, responder fosite.AccessResponder) (signature string, err error)

type JWTSession

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

JWTSession Container for the JWT session.

func (*JWTSession) Clone

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

func (*JWTSession) GetExpiresAt

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

func (*JWTSession) GetExtraClaims

func (s *JWTSession) GetExtraClaims() map[string]interface{}

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 fosite.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

	fosite.Session
}

type RFC9068JWTStrategy

type RFC9068JWTStrategy struct {
	*DefaultJWTStrategy
}

RFC9068JWTStrategy issues JWT access tokens conforming to RFC 9068

func (*RFC9068JWTStrategy) GenerateAccessToken

func (h *RFC9068JWTStrategy) GenerateAccessToken(ctx context.Context, requester fosite.Requester) (string, string, error)

type RefreshTokenGrantHandler

func (*RefreshTokenGrantHandler) CanHandleTokenEndpointRequest

func (c *RefreshTokenGrantHandler) CanHandleTokenEndpointRequest(ctx context.Context, requester fosite.AccessRequester) bool

func (*RefreshTokenGrantHandler) CanSkipClientAuth

func (c *RefreshTokenGrantHandler) CanSkipClientAuth(ctx context.Context, requester fosite.AccessRequester) bool

func (*RefreshTokenGrantHandler) HandleTokenEndpointRequest

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

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

func (*RefreshTokenGrantHandler) PopulateTokenEndpointResponse

func (c *RefreshTokenGrantHandler) PopulateTokenEndpointResponse(ctx context.Context, requester fosite.AccessRequester, responder fosite.AccessResponder) (err error)

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

type RefreshTokenStorage

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

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

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

	RotateRefreshToken(ctx context.Context, requestID string, refreshTokenSignature string) (err error)
}

type RefreshTokenStorageProvider

type RefreshTokenStorageProvider interface {
	RefreshTokenStorage() RefreshTokenStorage
}

type RefreshTokenStrategy

type RefreshTokenStrategy interface {
	RefreshTokenSignature(ctx context.Context, token string) string
	GenerateRefreshToken(ctx context.Context, requester fosite.Requester) (token string, signature string, err error)
	ValidateRefreshToken(ctx context.Context, requester fosite.Requester, token string) (err error)
}

type RefreshTokenStrategyProvider

type RefreshTokenStrategyProvider interface {
	RefreshTokenStrategy() RefreshTokenStrategy
}

type ResourceOwnerPasswordCredentialsGrantHandler deprecated

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, requester fosite.AccessRequester) bool

func (*ResourceOwnerPasswordCredentialsGrantHandler) CanSkipClientAuth

func (*ResourceOwnerPasswordCredentialsGrantHandler) HandleTokenEndpointRequest

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

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

func (*ResourceOwnerPasswordCredentialsGrantHandler) IssueAccessToken

func (c *ResourceOwnerPasswordCredentialsGrantHandler) IssueAccessToken(ctx context.Context, atLifespan time.Duration, requester fosite.AccessRequester, responder fosite.AccessResponder) (signature string, err error)

func (*ResourceOwnerPasswordCredentialsGrantHandler) PopulateTokenEndpointResponse

func (c *ResourceOwnerPasswordCredentialsGrantHandler) PopulateTokenEndpointResponse(ctx context.Context, requester fosite.AccessRequester, responder fosite.AccessResponder) error

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

type ResourceOwnerPasswordCredentialsGrantStorage

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

ResourceOwnerPasswordCredentialsGrantStorage provides storage for the resource owner password credentials grant.

type ResourceOwnerPasswordCredentialsGrantStorageProvider

type ResourceOwnerPasswordCredentialsGrantStorageProvider interface {
	ResourceOwnerPasswordCredentialsGrantStorage() ResourceOwnerPasswordCredentialsGrantStorage
}

ResourceOwnerPasswordCredentialsGrantStorageProvider provides the resource owner password credentials grant storage.

type Session

type Session interface {
	// SetSubject sets the session's subject.
	SetSubject(subject string)
}

type StatelessJWTValidator

type StatelessJWTValidator struct {
	jwt.Signer
	Config interface {
		fosite.ScopeStrategyProvider
	}
}

func (*StatelessJWTValidator) IntrospectToken

func (v *StatelessJWTValidator) IntrospectToken(ctx context.Context, token string, _ fosite.TokenUse, accessRequest fosite.AccessRequester, scopes []string) (fosite.TokenUse, error)

type TokenRevocationHandler

func (*TokenRevocationHandler) RevokeToken

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

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

type TokenRevocationStorage

type TokenRevocationStorage interface {
	// RevokeRefreshToken revokes a refresh token as specified in:
	// https://tools.ietf.org/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

	// RevokeAccessToken revokes an access token as specified in:
	// https://tools.ietf.org/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://tools.ietf.org/html/rfc7009

type TokenRevocationStorageProvider

type TokenRevocationStorageProvider interface {
	TokenRevocationStorage() TokenRevocationStorage
}

Jump to

Keyboard shortcuts

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