Help us shape the future of Go! Take the 2026 Go Developer Survey

oauthtest

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2026 License: Apache-2.0, CC-BY-4.0, MIT Imports: 16 Imported by: 0

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 both the authorization_code and refresh_token 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
}

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
}

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
}

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