Documentation
¶
Overview ¶
Package fosite provides custom OAuth 2.0 grant handlers for Ory Fosite.
This package enables agent authentication flows within Fosite-based OAuth servers by providing custom handlers for ID-JAG assertions and AAuth agent tokens.
Index ¶
Constants ¶
const ( // GrantTypeJWTBearer is the RFC 7523 JWT Bearer grant type. GrantTypeJWTBearer = "urn:ietf:params:oauth:grant-type:jwt-bearer" // GrantTypeTokenExchange is the RFC 8693 token exchange grant type. GrantTypeTokenExchange = "urn:ietf:params:oauth:grant-type:token-exchange" // GrantTypeAAuthAgent is the custom AAuth agent token grant type. GrantTypeAAuthAgent = "urn:ietf:params:oauth:grant-type:aauth-agent" )
Grant type constants for agent authentication.
const ( // TokenTypeJWT is the standard JWT token type. TokenTypeJWT = "urn:ietf:params:oauth:token-type:jwt" // TokenTypeAccessToken is an access token. TokenTypeAccessToken = "urn:ietf:params:oauth:token-type:access_token" // TokenTypeIDJAG is an ID-JAG assertion. TokenTypeIDJAG = "urn:ietf:params:oauth:token-type:id-jag" // TokenTypeAAuthAgent is an AAuth agent token. TokenTypeAAuthAgent = "urn:ietf:params:oauth:token-type:aa-agent+jwt" )
Token type constants.
Variables ¶
var ( ErrInvalidGrant = errors.New("ory: invalid grant") ErrInvalidAssertion = errors.New("ory: invalid assertion") ErrUnsupportedGrant = errors.New("ory: unsupported grant type") ErrVerificationError = errors.New("ory: token verification failed") ErrStorageError = errors.New("ory: storage operation failed") )
Error definitions.
Functions ¶
This section is empty.
Types ¶
type AAuthHandler ¶
type AAuthHandler struct {
// contains filtered or unexported fields
}
AAuthHandler handles AAuth agent token grants.
func NewAAuthHandler ¶
func NewAAuthHandler(issuer, jwksURL string, config HandlerConfig, storage TokenStorage) *AAuthHandler
NewAAuthHandler creates a new AAuth agent token handler.
func (*AAuthHandler) CanHandle ¶
func (h *AAuthHandler) CanHandle(req *TokenRequest) bool
CanHandle returns true if this handler can process the request.
func (*AAuthHandler) HandleTokenRequest ¶
func (h *AAuthHandler) HandleTokenRequest(ctx context.Context, req *TokenRequest) (*TokenResponse, error)
HandleTokenRequest processes an AAuth agent token grant.
func (*AAuthHandler) WithHTTPClient ¶
func (h *AAuthHandler) WithHTTPClient(client *http.Client) *AAuthHandler
WithHTTPClient sets a custom HTTP client.
type ActorData ¶
type ActorData struct {
// Subject is the actor's subject.
Subject string
// Issuer is the actor's issuer.
Issuer string
}
ActorData contains actor delegation information.
type AudienceStrategy ¶
type AudienceStrategy interface {
// ValidateAudience validates requested audiences.
ValidateAudience(requested []string) error
}
AudienceStrategy validates requested audiences.
type DefaultAudienceStrategy ¶
type DefaultAudienceStrategy struct{}
DefaultAudienceStrategy allows all audiences.
func (DefaultAudienceStrategy) ValidateAudience ¶
func (DefaultAudienceStrategy) ValidateAudience(_ []string) error
ValidateAudience always returns nil.
type DefaultScopeStrategy ¶
type DefaultScopeStrategy struct{}
DefaultScopeStrategy allows all requested scopes.
func (DefaultScopeStrategy) ValidateScopes ¶
func (DefaultScopeStrategy) ValidateScopes(requested, _ []string) ([]string, error)
ValidateScopes returns the requested scopes.
type HandlerConfig ¶
type HandlerConfig struct {
// Issuer is the OAuth server issuer URL.
Issuer string
// AccessTokenLifetime is the access token validity duration.
AccessTokenLifetime time.Duration
// RefreshTokenLifetime is the refresh token validity duration.
RefreshTokenLifetime time.Duration
// ScopeStrategy validates requested scopes.
ScopeStrategy ScopeStrategy
// AudienceStrategy validates requested audiences.
AudienceStrategy AudienceStrategy
}
HandlerConfig configures the token handler.
func DefaultHandlerConfig ¶
func DefaultHandlerConfig(issuer string) HandlerConfig
DefaultHandlerConfig returns a configuration with sensible defaults.
type IDJAGHandler ¶
type IDJAGHandler struct {
// contains filtered or unexported fields
}
IDJAGHandler handles ID-JAG assertion grants.
func NewIDJAGHandler ¶
func NewIDJAGHandler(verifier idjag.Verifier, config HandlerConfig, storage TokenStorage) *IDJAGHandler
NewIDJAGHandler creates a new ID-JAG assertion handler.
func (*IDJAGHandler) CanHandle ¶
func (h *IDJAGHandler) CanHandle(req *TokenRequest) bool
CanHandle returns true if this handler can process the request.
func (*IDJAGHandler) HandleTokenRequest ¶
func (h *IDJAGHandler) HandleTokenRequest(ctx context.Context, req *TokenRequest) (*TokenResponse, error)
HandleTokenRequest processes an ID-JAG assertion grant.
type MemoryStorage ¶
type MemoryStorage struct {
// contains filtered or unexported fields
}
MemoryStorage is an in-memory token storage for development/testing.
func NewMemoryStorage ¶
func NewMemoryStorage() *MemoryStorage
NewMemoryStorage creates a new in-memory token storage.
func (*MemoryStorage) CreateAccessToken ¶
CreateAccessToken creates and stores an access token.
func (*MemoryStorage) GetAccessToken ¶
GetAccessToken retrieves token data by token string.
func (*MemoryStorage) RevokeAccessToken ¶
func (s *MemoryStorage) RevokeAccessToken(_ context.Context, token string) error
RevokeAccessToken revokes an access token.
type ScopeStrategy ¶
type ScopeStrategy interface {
// ValidateScopes validates requested scopes against allowed scopes.
ValidateScopes(requested, allowed []string) ([]string, error)
}
ScopeStrategy validates and filters scopes.
type TokenData ¶
type TokenData struct {
// Subject is the token subject.
Subject string
// Issuer is the token issuer.
Issuer string
// Audience is the intended audience.
Audience []string
// Scopes are the granted scopes.
Scopes []string
// IssuedAt is when the token was issued.
IssuedAt time.Time
// ExpiresAt is when the token expires.
ExpiresAt time.Time
// ClientID is the OAuth client ID.
ClientID string
// Actor contains delegation information (optional).
Actor *ActorData
}
TokenData contains the data for an access token.
type TokenRequest ¶
type TokenRequest struct {
GrantType string
SubjectToken string
SubjectTokenType string
ActorToken string
ActorTokenType string
Scope []string
Audience []string
ClientID string
ClientSecret string
}
TokenRequest represents an OAuth token request.
type TokenResponse ¶
type TokenResponse struct {
AccessToken string `json:"access_token"`
TokenType string `json:"token_type"`
ExpiresIn int64 `json:"expires_in"`
RefreshToken string `json:"refresh_token,omitempty"`
Scope string `json:"scope,omitempty"`
IssuedTokenType string `json:"issued_token_type,omitempty"`
IssuedAt time.Time `json:"-"`
}
TokenResponse represents an OAuth token response.
type TokenStorage ¶
type TokenStorage interface {
// CreateAccessToken creates and stores an access token.
CreateAccessToken(ctx context.Context, data *TokenData) (string, error)
// GetAccessToken retrieves token data by token string.
GetAccessToken(ctx context.Context, token string) (*TokenData, error)
// RevokeAccessToken revokes an access token.
RevokeAccessToken(ctx context.Context, token string) error
}
TokenStorage provides token persistence.