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

mapper

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CELMapper

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

CELMapper is a ClaimMapper that uses CEL (Common Expression Language) expressions to produce claims from the MapperInput.

The CEL expression has access to the following variables and functions:

  • datasource(name) - function to fetch data from a named data source
  • now_ms() - current Unix time in milliseconds
  • fail(message) - reject as an internal/mapping failure (no OAuth error)
  • Layer A OAuth aborts: invalidRequest, invalidTarget, invalidGrant, …
  • Layer B reason helpers: invalidSubject, invalidActor, invalidAudience, unsupportedTokenType
  • subject - the subject identity information as a map
  • actor - the actor identity information as a map
  • request - the request attributes as a map

The expression should evaluate to a map that will be used as the claims, call a Layer A/B abort helper (Deny decision, err nil), or call fail() for an unexpected mapping/system failure (error).

Example CEL expressions:

// Simple claim from subject
{"user": subject.subject}

// Fetch from data source
{"roles": datasource("user_roles").roles}

// Policy guard (Layer B) then map
!has(subject.claims.idp)
  ? invalidSubject("claim 'idp' is required")
  : {"user": subject.subject}

// Reject unrecognised input (Layer B → invalid_request)
condition ? {"user": subject.subject} : unsupportedTokenType("unsupported_token_type")

// Complex expressions
{
  "user": subject.subject,
  "ip": request.ip_address,
  "roles": datasource("user_roles").roles,
  "region": datasource("geo").region
}

func NewCELMapper

func NewCELMapper(script string, opts ...CELMapperOption) (*CELMapper, error)

NewCELMapper creates a new CEL-based claim mapper. The script should be a CEL expression that evaluates to a map of claims.

func (*CELMapper) Map

Map evaluates the CEL expression and returns a MappingResult. Layer A/B OAuth abort helpers become Deny decisions with err == nil. fail() and other evaluation failures return error (unexpected).

func (*CELMapper) Script

func (m *CELMapper) Script() string

Script returns the CEL script used by this mapper

type CELMapperOption

type CELMapperOption func(*celMapperConfig)

CELMapperOption configures a CELMapper.

func WithClock

func WithClock(clk clock.Clock) CELMapperOption

WithClock sets the clock used by the now_ms() CEL function. Defaults to the system clock.

Jump to

Keyboard shortcuts

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