oidctest

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 14 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 is a fake OpenID Connect provider for tests: discovery, JWKS, an authorize endpoint that signs the configured user in at once, and a token endpoint that checks the client secret and PKCE and issues RS256 ID tokens. Tests rotate keys and break tokens on purpose.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Verified

func Verified(v bool) *bool

Verified is a pointer to true, for User.EmailVerified.

Types

type Provider

type Provider struct {
	Issuer string

	ClientID, ClientSecret string

	// Authorizations counts authorize requests.
	Authorizations int
	// LastChallenge is the PKCE challenge of the last authorize request.
	LastChallenge string
	// contains filtered or unexported fields
}

Provider is a running fake provider.

func New

func New(t testing.TB) *Provider

New starts a provider with one signing key and the user sub-1 / alice@acme.test (verified).

func (*Provider) BadSignature

func (p *Provider) BadSignature(on bool)

BadSignature makes later ID tokens carry a signature by an unpublished key under the published kid.

func (*Provider) Rotate

func (p *Provider) Rotate(keepOld bool)

Rotate publishes a new signing key; the old one stays published when keepOld is set (the usual overlap), otherwise it is dropped.

func (*Provider) SetUser

func (p *Provider) SetUser(u User)

SetUser sets who the next sign-ins are for.

func (*Provider) Sign

func (p *Provider) Sign(claims map[string]any) string

Sign makes an ID token from claims with the current key (applying Tamper and BadSignature), for tests that call a verifier directly.

func (*Provider) Tamper

func (p *Provider) Tamper(fn func(claims map[string]any))

Tamper changes the claims of later ID tokens (nil stops).

type User

type User struct {
	Subject       string
	Email         string
	EmailVerified *bool // nil: the claim is left out
	Name          string
}

User is who the fake provider signs in.

Jump to

Keyboard shortcuts

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