gauthtest

package
v0.25.2 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package gauthtest provides a fake Google OIDC issuer for offline tests of the gauth mint/verify paths — no network, no credentials, no test users.

Three pieces mirror the production topology:

  • MintIDToken signs RS256 ID tokens with a throwaway key (the fake "Google");
  • ClientOption returns an HTTP client option whose transport serves this issuer's JWKS, so gauth.Verifier validates those tokens for real (idtoken checks signature/expiry/audience against the fetched keys and does not pin the issuer);
  • TokenEndpoint + WriteServiceAccountKey fake the OAuth2 JWT-bearer grant: a fabricated service-account key whose token_uri points at the local endpoint lets idtoken.NewTokenSource (via GOOGLE_APPLICATION_CREDENTIALS) mint this issuer's tokens through the real client library path.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Issuer

type Issuer struct {
	Key   *rsa.PrivateKey
	KeyID string
}

Issuer is a fake Google OIDC token issuer backed by a throwaway RSA key.

func NewIssuer

func NewIssuer() (*Issuer, error)

NewIssuer generates the issuer's signing key.

func (*Issuer) ClientOption

func (i *Issuer) ClientOption() option.ClientOption

ClientOption returns the option to pass to gauth.Verifier so token validation fetches this issuer's JWKS instead of Google's.

func (*Issuer) MintIDToken

func (i *Issuer) MintIDToken(email, audience string, ttl time.Duration) (string, error)

MintIDToken signs an ID token for email/audience valid for ttl.

func (*Issuer) MintIDTokenClaims

func (i *Issuer) MintIDTokenClaims(claims map[string]any) (string, error)

MintIDTokenClaims signs an ID token with exactly the given claims — edge cases (expired, unverified email, missing claims) set them explicitly.

func (*Issuer) TokenEndpoint

func (i *Issuer) TokenEndpoint() *httptest.Server

TokenEndpoint starts a fake OAuth2 token endpoint implementing the JWT-bearer grant the way Google's does for ID tokens: it decodes the (unverified) assertion, reads the service account's email from `iss` and the requested audience from `target_audience`, and answers with an id_token minted by this issuer. Close the returned server when done.

func (*Issuer) WriteServiceAccountKey

func (i *Issuer) WriteServiceAccountKey(dir, email, tokenURL string) (string, error)

WriteServiceAccountKey writes a fabricated service-account key file whose token_uri points at tokenURL, and returns its path. Point GOOGLE_APPLICATION_CREDENTIALS at it so idtoken.NewTokenSource mints through the real JWT-bearer flow against the fake endpoint.

Jump to

Keyboard shortcuts

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