oidctest

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: MIT Imports: 20 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

Overview

Package oidctest provides an OpenID Connect provider for tests. It logs in every authorization request as the configured user, unless the user is logged out and the request asks for prompt=none.

Index

Constants

View Source
const (
	ClientSecret = "secret"
)

Variables

View Source
var ErrDPoPNonce = errors.New("dpop nonce required")

ErrDPoPNonce is returned by VerifyDPoPProof when the proof does not have the required nonce.

Functions

func VerifyDPoPProof

func VerifyDPoPProof(r *http.Request, accessToken, nonce string) (string, error)

VerifyDPoPProof verifies the DPoP proof of a request received by a server, as defined by RFC 9449 4.3, and returns the JWK thumbprint of its key. The proof must be bound to the access token and have the nonce when they are not empty.

Types

type Assertion

type Assertion struct {
	Path  string
	Alg   string
	KeyID string
}

Assertion is a private_key_jwt assertion accepted by the provider.

type EndSession

type EndSession struct {
	IDTokenHint           string
	PostLogoutRedirectURI string
	ClientID              string
}

EndSession is a request to the end session endpoint.

type Options

type Options struct {
	// ClientKey is the public key that verifies the private_key_jwt assertions and the request objects of the clients.
	ClientKey crypto.PublicKey
	// Metadata is added to the discovery document. A nil value removes a field.
	Metadata map[string]any
	// Claims are added to the ID tokens. A nil value removes a claim.
	Claims map[string]any
	// UserInfo is added to the UserInfo response.
	UserInfo map[string]any
	// ISS is the iss parameter of the authorization response, sent when the discovery document advertises it. The
	// default is the issuer.
	ISS     string
	Subject string
	SID     string
	// DPoPNonce is the nonce the token endpoint requires in the DPoP proofs, when it is not empty.
	DPoPNonce string
	// InvalidTargets are the resources the token endpoint rejects with invalid_target (RFC 8707 2).
	InvalidTargets []string
	// AccessTokenTTL is the lifetime of the access tokens. The default is 5 minutes.
	AccessTokenTTL time.Duration
	// UserInfoStatus is the status of the UserInfo responses, when it is not zero.
	UserInfoStatus int
	// RotateRefreshTokens issues a new refresh token on every refresh. Reusing a refresh token then revokes every
	// token issued from it.
	RotateRefreshTokens bool
	LoggedOut           bool
	// PAR advertises the pushed authorization request endpoint.
	PAR bool
	// DecoyKeys adds to the key set the keys a client must ignore, as the OpenID conformance suite does.
	DecoyKeys bool
	// IgnoreDPoP issues bearer access tokens to the requests with a DPoP proof.
	IgnoreDPoP bool
	// Plain serves the provider over HTTP, for browser tests. It is read once by [NewServer].
	Plain bool
}

Options configures a Server. Every field can be changed while the server runs, with Server.Update.

type RequestObject

type RequestObject struct {
	Claims map[string]any
	Alg    string
	KeyID  string
}

RequestObject is a request object accepted by the pushed authorization request endpoint.

type Server

type Server struct {
	*httptest.Server
	// contains filtered or unexported fields
}

Server is an OpenID Connect provider served over TLS.

func NewServer

func NewServer(opts Options) *Server

NewServer starts a Server.

func (*Server) AccessTokenResource

func (s *Server) AccessTokenResource(accessToken string) (string, bool)

AccessTokenResource returns the resource of an access token issued by the provider, which is empty for an access token requested without resource.

func (*Server) Assertions

func (s *Server) Assertions() []Assertion

Assertions returns the private_key_jwt assertions accepted by the provider.

func (*Server) EndSessions

func (s *Server) EndSessions() []EndSession

EndSessions returns the requests received by the end session endpoint.

func (*Server) LogoutToken

func (s *Server) LogoutToken(clientID, sub, sid string) string

LogoutToken returns a valid back-channel logout token for the client. An empty sub or sid is omitted.

func (*Server) Refreshes

func (s *Server) Refreshes() int

Refreshes returns the number of refresh token grants accepted by the provider.

func (*Server) RequestObjects

func (s *Server) RequestObjects() []RequestObject

RequestObjects returns the request objects accepted by the provider.

func (*Server) Revoked

func (s *Server) Revoked() []string

Revoked returns the tokens revoked through the revocation endpoint.

func (*Server) RotateKey

func (s *Server) RotateKey()

RotateKey replaces the provider key with a new key, published with a new key ID.

func (*Server) Sign

func (s *Server) Sign(typ string, claims map[string]any) string

Sign returns a JWT with the given claims and typ header, signed by the provider key.

func (*Server) Update

func (s *Server) Update(fn func(o *Options))

Update changes the options of a running server.

Jump to

Keyboard shortcuts

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