oauthtest

package
v1.9.0-pre.1 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: Apache-2.0, CC-BY-4.0, MIT Imports: 16 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClientCredentialsConfig added in v1.6.0

type ClientCredentialsConfig struct {
	// Enabled controls whether the /token endpoint accepts
	// grant_type=client_credentials and returns an access token
	// if client authentication succeeds.
	Enabled bool
}

ClientCredentialsConfig configures support for the client_credentials grant type (RFC 6749 Section 4.4) on a FakeAuthorizationServer.

type ClientInfo

type ClientInfo struct {
	Secret       string
	RedirectURIs []string
}

type Config

type Config struct {
	// The optional path component of the issuer URL.
	// If non-empty, it should start with a "/". It should not end with a "/".
	// It affects the paths of the server endpoints.
	IssuerPath string
	// Configuration of the metadata endpoint.
	MetadataEndpointConfig *MetadataEndpointConfig
	// Configuration for client registration.
	RegistrationConfig *RegistrationConfig
	// JWTBearerConfig enables RFC 7523 JWT Bearer grant at the /token endpoint.
	// If non-nil, the server accepts grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer.
	JWTBearerConfig *JWTBearerConfig
	// ClientCredentialsConfig enables RFC 6749 Section 4.4 client credentials
	// grant at the /token endpoint.
	ClientCredentialsConfig *ClientCredentialsConfig
	// ScopesSupported is an optional list of scopes to advertise in the
	// authorization server metadata.
	ScopesSupported []string
	// TokenScopeFunc, if set, is called with the scope from the authorization
	// request and returns the scope string to include in the token response.
	TokenScopeFunc func(requestedScope string) string
	// AccessTokenTTL, if non-zero, is the expires_in (in seconds) returned by the
	// /token endpoint for the authorization_code, refresh_token and
	// client_credentials grants. When zero a default of 3600 is used. Set it
	// small to force a client's reuse token source to treat the access token as
	// expired and refresh it.
	AccessTokenTTL int
	// IssueRefreshToken, if true, includes a refresh_token in token responses and
	// enables grant_type=refresh_token at the /token endpoint.
	IssueRefreshToken bool
	// UnadvertiseIssParameter, if true, omits
	// authorization_response_iss_parameter_supported from metadata while the
	// authorize endpoint still includes iss. Used to test local policy for
	// unadvertised RFC 9207 iss.
	UnadvertiseIssParameter bool
	// OmitPKCEMethods, if true, omits code_challenge_methods_supported from
	// metadata, as an authorization server without an authorization code
	// flow does.
	OmitPKCEMethods bool
}

Config holds configuration for FakeAuthorizationServer.

type FakeAuthorizationServer

type FakeAuthorizationServer struct {
	Mux *http.ServeMux
	// contains filtered or unexported fields
}

FakeAuthorizationServer is a fake OAuth 2.0 Authorization Server for testing.

func NewFakeAuthorizationServer

func NewFakeAuthorizationServer(config Config) *FakeAuthorizationServer

NewFakeAuthorizationServer creates a new FakeAuthorizationServer. The server is simple and should not be used outside of testing. It supports: - Only the authorization Code Grant - PKCE verification - Client tracking & dynamic registration - Client authentication

func (*FakeAuthorizationServer) Start

func (s *FakeAuthorizationServer) Start(t testing.TB)

Start starts the HTTP server and registers a cleanup function on t to close the server.

func (*FakeAuthorizationServer) URL

URL returns the base URL of the server (Issuer).

type FakeIdPServer added in v1.6.0

type FakeIdPServer struct {
	// contains filtered or unexported fields
}

FakeIdPServer is a fake OIDC Identity Provider for testing. It supports:

  • OIDC discovery (/.well-known/openid-configuration)
  • Authorization Code Grant with PKCE
  • ID Token issuance (fake JWTs)
  • RFC 8693 Token Exchange (ID Token → ID-JAG), if configured

func NewFakeIdPServer added in v1.6.0

func NewFakeIdPServer(config IdPConfig) *FakeIdPServer

NewFakeIdPServer creates a new FakeIdPServer.

func (*FakeIdPServer) Start added in v1.6.0

func (s *FakeIdPServer) Start(t testing.TB)

Start starts the HTTP server and registers a cleanup function on t.

func (*FakeIdPServer) URL added in v1.6.0

func (s *FakeIdPServer) URL() string

URL returns the base URL of the server (issuer).

type IdPConfig added in v1.6.0

type IdPConfig struct {
	// PreregisteredClients maps client IDs to their info.
	PreregisteredClients map[string]ClientInfo

	// TokenExchangeConfig enables RFC 8693 token exchange at the /token endpoint.
	// If non-nil, the server accepts grant_type=urn:ietf:params:oauth:grant-type:token-exchange.
	TokenExchangeConfig *TokenExchangeConfig

	// IssParameterSupported advertises authorization_response_iss_parameter_supported
	// and adds the iss parameter to authorization responses (RFC 9207).
	IssParameterSupported bool

	// OmitPKCEMethods omits code_challenge_methods_supported from the metadata.
	OmitPKCEMethods bool
}

IdPConfig holds configuration for FakeIdPServer.

type JWTBearerConfig added in v1.6.0

type JWTBearerConfig struct {
	// ValidAssertions is the set of assertion values that are accepted.
	// If empty, any non-empty assertion is accepted.
	ValidAssertions []string
}

JWTBearerConfig configures support for the JWT Bearer grant type (RFC 7523) on a FakeAuthorizationServer.

type MetadataEndpointConfig

type MetadataEndpointConfig struct {
	// Whether to serve the OAuth Authorization Server Metadata at
	// /.well-known/oauth-authorization-server + issuerPath.
	ServeOAuthInsertedEndpoint bool
	// Whether to serve the OAuth Authorization Server Metadata at
	// /.well-known/openid-configuration + issuerPath.
	ServeOpenIDInsertedEndpoint bool
	// Whether to serve the OAuth Authorization Server Metadata at
	// issuerPath + /.well-known/openid-configuration.
	// Should be used when issuerPath is not empty.
	ServeOpenIDAppendedEndpoint bool
}

type RegistrationConfig

type RegistrationConfig struct {
	// Whether the client ID metadata document is supported.
	ClientIDMetadataDocumentSupported bool
	// PreregisteredClients is a map of valid ClientIDs to ClientSecrets.
	PreregisteredClients map[string]ClientInfo
	// Whether dynamic client registration is enabled.
	DynamicClientRegistrationEnabled bool
}

type TokenExchangeConfig added in v1.6.0

type TokenExchangeConfig struct {
	// IDJAGToken is the ID-JAG value returned from token exchange.
	// Defaults to "test-id-jag-token" if empty.
	IDJAGToken string

	// IssuedTokenType is the issued_token_type returned from token exchange.
	// Defaults to oauthex.TokenTypeIDJAG if empty.
	IssuedTokenType string
}

TokenExchangeConfig configures RFC 8693 token exchange support on a FakeIdPServer.

Jump to

Keyboard shortcuts

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