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

oauth

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClaimValues added in v0.1.3

func ClaimValues(claims map[string]any, path string) []string

ClaimValues returns string values at a dotted JSON path. Missing paths yield nil. Strings, string arrays, and numeric scalars are collected; objects are ignored.

func DecodeIDTokenClaims added in v0.1.3

func DecodeIDTokenClaims(idToken string) (map[string]any, error)

DecodeIDTokenClaims base64-decodes the JWT payload. Signature verification is intentionally skipped.

func EmailDomain added in v0.1.3

func EmailDomain(email string) string

EmailDomain returns the exact domain after the last "@", lowercased.

func MapOrganization added in v0.1.3

func MapOrganization(in OrganizationMapping) (string, error)

MapOrganization returns an organization name or UUID to resolve. Precedence: allowlisted email domain, then mapped org claim, then domain→org map, then default. A present org claim that matches nothing is denied (no domain/default fallback).

func MapRole added in v0.1.3

func MapRole(claims map[string]any, roleClaim string, roleMap []config.ClaimMapEntry, defaultRole string) (string, error)

MapRole returns the IPAM role for JIT provisioning. If any mapped claim value is admin, admin wins; else user if mapped; else the default role.

func MergeTokenClaims added in v0.1.3

func MergeTokenClaims(userinfo map[string]any, token *oauth2.Token) map[string]any

MergeTokenClaims overlays ID-token claims on userinfo. The token is the one returned by the configured token endpoint after a confidential-client code exchange; the JWT signature is not re-verified.

Types

type OrganizationMapping added in v0.1.3

type OrganizationMapping struct {
	Claims         map[string]any
	Email          string
	OrgClaim       string
	OrgMap         []config.ClaimMapEntry
	DefaultOrg     string
	AllowedDomains []string
	DomainOrgMap   []config.ClaimMapEntry
}

OrganizationMapping is the input for JIT organization resolution.

type ProviderRegistry

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

func NewProviderRegistry

func NewProviderRegistry(cfg *config.Config) (*ProviderRegistry, error)

func (*ProviderRegistry) Endpoint

func (r *ProviderRegistry) Endpoint(providerID string) (oauth2.Endpoint, bool)

func (*ProviderRegistry) HTTPClient added in v0.1.1

func (r *ProviderRegistry) HTTPClient(providerID string) *http.Client

func (*ProviderRegistry) Register

func (r *ProviderRegistry) Register(providerID string, endpoint oauth2.Endpoint, fetcher UserInfoFetcher, client *http.Client)

func (*ProviderRegistry) UserInfo

func (r *ProviderRegistry) UserInfo(ctx context.Context, providerID string, token *oauth2.Token) (*UserProfile, error)

type UserInfoFetcher

type UserInfoFetcher interface {
	FetchUser(ctx context.Context, token *oauth2.Token) (*UserProfile, error)
}

type UserProfile added in v0.1.3

type UserProfile struct {
	ProviderUserID string
	Email          string
	Claims         map[string]any
}

UserProfile is identity plus the claim map from userinfo (and, after MergeTokenClaims, the ID token).

Jump to

Keyboard shortcuts

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