Documentation
¶
Overview ¶
Package core implements OAuth 2.0 provider discovery, client authentication, token grants, parsing, and safe native values.
Index ¶
- Variables
- func AuthorizationHeader(token *TokenSet) (map[string]string, error)
- type Client
- type ClientAuthMethod
- type ClientConfig
- type ClientCredentialsOptions
- type Clock
- type ClockFunc
- type DiscoveryOptions
- type Error
- type Executor
- func (e *Executor) ClientCredentials(ctx context.Context, client *Client, options ClientCredentialsOptions) (*TokenSet, error)
- func (e *Executor) Refresh(ctx context.Context, client *Client, previous *TokenSet, ...) (*TokenSet, error)
- func (e *Executor) Token(ctx context.Context, client *Client, options TokenOptions) (*TokenSet, error)
- type ExecutorOption
- type Parameters
- type Provider
- type ProviderConfig
- type RefreshOptions
- type TokenOptions
- type TokenSet
- func (t *TokenSet) Clone() *TokenSet
- func (t TokenSet) Expired(now time.Time, skew time.Duration) bool
- func (t TokenSet) Format(state fmt.State, verb rune)
- func (t TokenSet) MarshalJSON() ([]byte, error)
- func (t TokenSet) MarshalMsgpack() ([]byte, error)
- func (t TokenSet) Scopes() []string
- func (t TokenSet) String() string
- func (t TokenSet) ValidFor(now time.Time) (time.Duration, bool)
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidExecutor indicates invalid token executor configuration. ErrInvalidExecutor = errors.New("invalid OAuth2 token executor") // ErrInvalidGrant indicates invalid grant input. ErrInvalidGrant = errors.New("invalid OAuth2 grant") // ErrInvalidTokenResponse indicates a malformed token endpoint response. ErrInvalidTokenResponse = errors.New("invalid OAuth2 token response") )
Functions ¶
Types ¶
type Client ¶
type Client struct {
Provider *Provider
ClientID string
ClientSecret string
AuthMethod ClientAuthMethod
}
Client contains an OAuth provider and the credentials used at its token endpoint.
func NewClient ¶
func NewClient(provider *Provider, config ClientConfig) (*Client, error)
NewClient constructs and validates an OAuth client.
func (*Client) MarshalJSON ¶
MarshalJSON returns a safe representation of the client.
func (*Client) MarshalMsgpack ¶
MarshalMsgpack serializes a redacted client view.
type ClientAuthMethod ¶
type ClientAuthMethod string
ClientAuthMethod identifies how an OAuth client authenticates at the token endpoint.
const ( // ClientAuthMethodNone sends no client secret. ClientAuthMethodNone ClientAuthMethod = "none" // ClientAuthMethodBasic sends the client credentials in an Authorization // header using the client_secret_basic method. ClientAuthMethodBasic ClientAuthMethod = "client_secret_basic" // ClientAuthMethodPost sends the client credentials in the form body using // the client_secret_post method. ClientAuthMethodPost ClientAuthMethod = "client_secret_post" )
type ClientConfig ¶
type ClientConfig struct {
ClientID string
ClientSecret string
AuthMethod ClientAuthMethod
}
ClientConfig configures an OAuth client.
type ClientCredentialsOptions ¶
type ClientCredentialsOptions struct {
Parameters Parameters
Audience string
Scope []string
Timeout time.Duration
}
ClientCredentialsOptions configures a client credentials grant.
type DiscoveryOptions ¶
DiscoveryOptions controls authorization-server metadata discovery.
type Error ¶
Error is an OAuth protocol error returned by a token endpoint.
func (*Error) MarshalJSON ¶
MarshalJSON serializes only normalized OAuth error fields.
type Executor ¶
type Executor struct {
// contains filtered or unexported fields
}
Executor performs OAuth token grants with an injected Ferret HTTP client.
func NewExecutor ¶
func NewExecutor(httpClient ferrethttp.Client, options ...ExecutorOption) (*Executor, error)
NewExecutor constructs a token grant executor.
func (*Executor) ClientCredentials ¶
func (e *Executor) ClientCredentials( ctx context.Context, client *Client, options ClientCredentialsOptions, ) (*TokenSet, error)
ClientCredentials exchanges client credentials for a token.
type ExecutorOption ¶
ExecutorOption configures an Executor.
func WithClock ¶
func WithClock(clock Clock) ExecutorOption
WithClock sets the clock used to calculate token expiry.
type Parameters ¶
Parameters contains provider-specific form fields. Each value is emitted as a separate form field, preserving repeated parameters.
type Provider ¶
type Provider struct {
Issuer string
AuthorizationEndpoint string
TokenEndpoint string
RevocationEndpoint string
IntrospectionEndpoint string
JWKSURI string
ScopesSupported []string
GrantTypesSupported []string
TokenEndpointAuthMethods []string
// contains filtered or unexported fields
}
Provider describes an OAuth authorization server and its advertised capabilities.
func Discover ¶
func Discover( ctx context.Context, httpClient ferrethttp.Client, issuer string, options DiscoveryOptions, ) (*Provider, error)
Discover loads and validates RFC 8414 authorization-server metadata.
func NewProvider ¶
func NewProvider(config ProviderConfig) (*Provider, error)
NewProvider constructs and validates an OAuth provider.
func (*Provider) Format ¶
Format keeps all fmt formatting variants on the secret-safe representation.
func (*Provider) MarshalJSON ¶
MarshalJSON returns the provider's safe public configuration.
func (*Provider) MarshalMsgpack ¶
MarshalMsgpack serializes the provider's safe public configuration.
type ProviderConfig ¶
type ProviderConfig struct {
Issuer string
AuthorizationEndpoint string
TokenEndpoint string
RevocationEndpoint string
IntrospectionEndpoint string
JWKSURI string
ScopesSupported []string
GrantTypesSupported []string
TokenEndpointAuthMethods []string
InsecureAllowHTTP bool
}
ProviderConfig configures an OAuth authorization server.
type RefreshOptions ¶
type RefreshOptions struct {
Parameters Parameters
RefreshToken string
Scope []string
Timeout time.Duration
}
RefreshOptions configures a refresh token grant.
type TokenOptions ¶
type TokenOptions struct {
Parameters Parameters
Timeout time.Duration
}
TokenOptions configures an OAuth extension grant.
type TokenSet ¶
type TokenSet struct {
ExpiresAt time.Time
Extra map[string]any
AccessToken string
TokenType string
RefreshToken string
Scope string
IDToken string
ExpiresIn time.Duration
}
TokenSet represents a token endpoint response.
func (TokenSet) Expired ¶
Expired reports whether the token is expired at now after applying skew. A token with no known expiry is not considered expired.
func (TokenSet) MarshalJSON ¶
MarshalJSON serializes a redacted, stable token view.
func (TokenSet) MarshalMsgpack ¶
MarshalMsgpack serializes a redacted token view.
Source Files
¶
- authorization_header.go
- client.go
- client_auth_method.go
- client_config.go
- clock.go
- discovery.go
- doc.go
- error.go
- executor.go
- executor_options.go
- grant_options.go
- parameters.go
- provider.go
- provider_config.go
- provider_url.go
- request_error.go
- safe_json.go
- secret_sanitizer.go
- sentinels.go
- token_extra.go
- token_response.go
- token_set.go