Documentation
¶
Index ¶
- func GenericClaims[C any, T interface{ ... }](ctx context.Context, hasValidClaims func(claims map[string]any) bool, ...) map[string]any
- func GenericExtract[C any, T interface{ ... }](ctx context.Context, hasValidClaims func(claims map[string]any) bool) (string, error)
- func GenericIsService[C any, T interface{ ... }](ctx context.Context, hasValidClaims func(claims map[string]any) bool) bool
- func GenericRoles(roleMapper mapper.Mapper, claims map[string]any) []string
- func HasAnyNonEmptyString(m map[string]any, keys ...string) bool
- func HasNonEmptyString(m map[string]any, key string) bool
- type ClaimsMapper
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenericClaims ¶ added in v0.8.0
func GenericClaims[C any, T interface { *C ClaimsMapper }](ctx context.Context, hasValidClaims func(claims map[string]any) bool, fallback func(ctx context.Context, custom map[string]any) map[string]any) map[string]any
GenericClaims returns the typed claims flattened via ClaimsMap on the typed path, or fallback(ctx, custom) on the generic-fallback path once custom has been confirmed valid by hasValidClaims. Returns an empty map when neither path yields claims.
func GenericExtract ¶ added in v0.8.0
func GenericExtract[C any, T interface { *C ClaimsMapper }](ctx context.Context, hasValidClaims func(claims map[string]any) bool) (string, error)
GenericExtract returns the principal subject from ctx for provider C/T.
func GenericIsService ¶ added in v0.8.0
func GenericIsService[C any, T interface { *C ClaimsMapper }](ctx context.Context, hasValidClaims func(claims map[string]any) bool) bool
GenericIsService reports whether ctx carries a valid token for provider C/T, on either the typed or generic-fallback path.
func GenericRoles ¶ added in v0.8.0
GenericRoles maps claims via roleMapper, or returns nil when roleMapper is nil.
func HasAnyNonEmptyString ¶
HasAnyNonEmptyString returns true if any of the provided keys in the map contain a non-empty string value.
Types ¶
type ClaimsMapper ¶ added in v0.8.0
type ClaimsMapper interface {
// ClaimsMap returns the typed claims as a flat map, seeded with any
// canonical keys (e.g. "username") the provider wants alongside its raw
// claim names. subject is the token's registered "sub" claim (may be
// empty); implementations that don't derive "username" from it can
// ignore the parameter.
ClaimsMap(subject string) map[string]any
}
ClaimsMapper is implemented by provider-specific typed OIDC claims types (e.g. aws.Claims, flyio.Claims, githubactions.Claims) so the Generic* helpers below can flatten typed claims into the map[string]any shape ClaimRoleMapper rules and PrincipalSource.Claims callers expect.