testidp

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package testidp is a stand-in OpenID provider for tests: discovery, a signing key, an authorization endpoint and a token endpoint that hold a relying party to the parts of the protocol the registry depends on (the registered client, PKCE, single-use codes, the nonce), and sign real ID tokens for whoever a test says is signing in. A test signs people in through it the way a deployment's own OpenID provider would, with no directory and no password anywhere.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IdP

type IdP struct {
	URL          string
	ClientID     string
	ClientSecret string
	// contains filtered or unexported fields
}

IdP is one running stand-in provider. Its issuer is URL; the registry is registered as ClientID with ClientSecret.

func New

func New(t testing.TB) *IdP

New starts a provider for the test's lifetime.

func (*IdP) Authorize

func (p *IdP) Authorize(t testing.TB, authURL string) (code, state string)

Authorize is the browser's visit to the authorization URL the relying party redirected to: it returns the code and the state the provider sends back to the redirect URI, for the person SignInAs named. An authorization the provider refuses fails the test.

func (*IdP) Client

func (p *IdP) Client() *http.Client

Client reaches the provider; hand it to the relying party for discovery and the code exchange.

func (*IdP) SignInAs

func (p *IdP) SignInAs(person Person)

SignInAs makes person the one the next authorization is for.

type Person

type Person struct {
	// Subject is the token's `sub`.
	Subject string
	// Email and EmailVerified are `email` and `email_verified`.
	Email         string
	EmailVerified bool
	// Username is `preferred_username`, omitted when empty.
	Username string
	// AMR is `amr`, omitted when nil.
	AMR []string
	// AuthTime is `auth_time`, omitted when zero.
	AuthTime time.Time
	// Claims ride the token as given, over the ones above.
	Claims map[string]any
}

Person is who the next sign-in is for, and what the ID token says of them.

Jump to

Keyboard shortcuts

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