edgeauthtest

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: MIT Imports: 13 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 edgeauthtest mints identity JWTs for an app's tests, the way guard signs them, with a throwaway key served from an in-process JWKS:

iss := edgeauthtest.NewIssuer(t)
v, err := edgeauth.New(iss.Config("live.metsa.app"))
...
req := httptest.NewRequest(http.MethodGet, "https://live.metsa.app/admin", nil)
iss.Sign(req, edgeauth.Identity{Subject: "u1", Roles: []string{"admin"}})

MintWith edits the claims before signing, for the tokens an app must refuse (expired, for another host).

Index

Constants

View Source
const KeyID = "edgeauthtest"

KeyID is the kid of every Issuer's key.

View Source
const Lifetime = 60 * time.Second

Lifetime is how long a minted token is valid, as guard's are.

Variables

This section is empty.

Functions

This section is empty.

Types

type Claims

type Claims struct {
	Issuer        string   `json:"iss"`
	Audience      string   `json:"aud"`
	Subject       string   `json:"sub"`
	Email         string   `json:"email"`
	EmailVerified bool     `json:"email_verified"`
	Name          string   `json:"name"`
	Roles         []string `json:"roles"`
	SessionID     string   `json:"sid"`
	AuthTime      int64    `json:"auth_time,omitempty"`
	ClientID      string   `json:"azp"`
	Source        string   `json:"src"`
	IssuedAt      int64    `json:"iat"`
	Expiry        int64    `json:"exp"`
}

Claims is a token's payload before signing, for MintWith to edit.

type Issuer

type Issuer struct {
	// contains filtered or unexported fields
}

Issuer signs identity JWTs with an in-memory P-256 key and serves its JWKS on a test server that is closed when the test ends.

func NewIssuer

func NewIssuer(t testing.TB) *Issuer

NewIssuer starts an Issuer for the test.

func (*Issuer) Config

func (i *Issuer) Config(aud ...string) edgeauth.Config

Config is a verifier config that trusts this Issuer for the hosts aud.

func (*Issuer) JWKSURL

func (i *Issuer) JWKSURL() string

JWKSURL is where the Issuer serves its public key.

func (*Issuer) Mint

func (i *Issuer) Mint(id edgeauth.Identity, aud string) string

Mint signs an identity JWT for id with audience aud, issued now and valid for Lifetime. An empty Source becomes edgeauth.SourceSession.

func (*Issuer) MintWith

func (i *Issuer) MintWith(id edgeauth.Identity, aud string, edit func(*Claims)) string

MintWith is Mint with edit applied to the claims before signing.

func (*Issuer) Sign

func (i *Issuer) Sign(r *http.Request, id edgeauth.Identity)

Sign sets r's identity header to a token for id, with the audience guard would use: r's host, lower case, without the port.

Jump to

Keyboard shortcuts

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