subject

package
v0.69.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: Apache-2.0 Imports: 6 Imported by: ? 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 subject maps a user's identity at an issuer, one claim and its value, to the local user it belongs to. Callers build the key from the token they hold: the upstream_subject claim of an ID-JAG from a ToolHive authorization server, or the configured binding claim of a token that an identity provider issued directly.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotConfigured means the resolver does not resolve this issuer and
	// claim. It is a property of the Ref, not of the user: no value of this
	// issuer and claim would resolve. Callers refuse the token.
	ErrNotConfigured = errors.New("subject issuer or claim not configured")
	// ErrUnknown means no local user matches the Ref. Callers refuse the token.
	ErrUnknown = errors.New("unknown subject")
	// ErrAmbiguous means more than one local user matches the Ref. Callers
	// refuse the token. Directory-backed resolvers return it; the standalone
	// resolver never does.
	ErrAmbiguous = errors.New("ambiguous subject")
	// ErrUnavailable means the resolver could not answer. Callers report a
	// server error, not invalid_grant, so the client may retry.
	ErrUnavailable = errors.New("subject resolver unavailable")
)
View Source
var ErrInvalidBindingClaim = errors.New("invalid binding claim")

ErrInvalidBindingClaim means a configured binding claim cannot identify a local user.

Functions

func ValidateBindingClaim

func ValidateBindingClaim(issuer, claim string) (warning string, err error)

ValidateBindingClaim checks the claim that maps a token's subject to a local user, for the token issuer named by issuer. A known mutable claim name (such as email, preferred_username, upn, unique_name or name, in any letter case), an empty claim, or a claim with surrounding whitespace is refused. A claim that passes is not proven stable: prefer sub, oid or uid. A non-empty warning means the claim is sub on an Okta custom authorization server; the caller decides how to report it.

Types

type Ref

type Ref struct {
	// Issuer is the issuer the claim belongs to. For an upstream_subject claim
	// that is the identity provider, not the server that signed the token.
	Issuer string
	// Claim is the name of the claim, such as "sub".
	Claim string
	// Value is the claim's value.
	Value string
}

Ref is a lookup key for a subject: one claim, with its value, from one issuer.

It has the shape of the https://toolhive.dev/upstream_subject claim ({iss, claim, value}). From ToolHive's own record of an upstream login (session.UpstreamSubject, tokenexchange.UpstreamIdentity) it is {Issuer, StableClaim, StableValue}; the raw sub is not part of the key.

type Resolver

type Resolver interface {
	Resolve(ctx context.Context, ref Ref) (string, error)
}

Resolver maps a Ref to the canonical local user ID.

A nil error always comes with a non-empty user ID. Resolvers never create users; a Ref with no local user returns ErrUnknown. A Ref whose issuer or claim the resolver does not resolve at all returns ErrNotConfigured, so a caller can tell a wrong assertion from a user that is not provisioned. Callers log the errors an implementation returns, so they must not include the Ref's values.

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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