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 ¶
func (m *CELMapper) Map(ctx context.Context, input *service.MapperInput) (service.MappingResult, error)
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).
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.