Help us shape the future of Go! Take the 2026 Go Developer Survey

client

package
v1.23.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

Package client is the holder's side of an API key: the assertion it signs with the private half of a key its account registered, wherever that half is kept -- a file, a key manager, a TPM, anything a crypto.Signer reaches -- and the exchange of the assertion for a session token at the login service's token endpoint.

The assertion is the one package assertion verifies: RFC 7523's shape, typed "api-key+jwt", naming the key by its RFC 7638 thumbprint in "iss" and "sub", bound to the login service by "aud", good for a minute, and new every time by its "jti".

Index

Constants

View Source
const AssertionLifetime = time.Minute

AssertionLifetime is how long an assertion is good for: one request's worth, well inside what the service accepts.

View Source
const TokenPath = "/api/token"

TokenPath is where the login service exchanges an assertion for a token.

Variables

View Source
var ErrRefused = errors.New("the login service refused the assertion")

ErrRefused is the login service's refusal of an assertion, or an answer with no token in it.

Functions

func Assert

func Assert(signer crypto.Signer, audience string, now time.Time) (string, error)

Assert signs an assertion for the audience -- the login service's origin -- at the instant now, with the key the signer holds the private half of.

Types

type Source

type Source struct {
	Signer     crypto.Signer
	Service    *url.URL
	HttpClient *http.Client
	// Margin is how long before its end a token is no longer handed out; a minute if not given.
	Margin time.Duration
	// Now is the clock; time.Now if not given.
	Now func() time.Time
	// contains filtered or unexported fields
}

Source is a token kept until near its end and minted again then: what a job that calls a service now and again holds rather than minting for every call.

func (*Source) Token

func (s *Source) Token(ctx context.Context) (string, error)

Token is a token good for at least the margin, the one kept if it still is.

type Token

type Token struct {
	AccessToken string
	ExpiresAt   time.Time
}

Token is a session token minted against the key, and when it stops being good.

func Mint

func Mint(ctx context.Context, httpClient *http.Client, service *url.URL, assertionString string, now time.Time) (*Token, error)

Mint exchanges the assertion for a token at the login service's token endpoint.

Jump to

Keyboard shortcuts

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