22 lines
606 B
Go
22 lines
606 B
Go
package identity
|
|
|
|
import "context"
|
|
|
|
type Principal struct {
|
|
Issuer string `json:"issuer"`
|
|
Subject string `json:"subject"`
|
|
DisplayName string `json:"display_name,omitempty"`
|
|
PreferredUsername string `json:"preferred_username,omitempty"`
|
|
}
|
|
|
|
type principalContextKey struct{}
|
|
|
|
func WithPrincipal(ctx context.Context, principal Principal) context.Context {
|
|
return context.WithValue(ctx, principalContextKey{}, principal)
|
|
}
|
|
|
|
func PrincipalFromContext(ctx context.Context) (Principal, bool) {
|
|
principal, ok := ctx.Value(principalContextKey{}).(Principal)
|
|
return principal, ok
|
|
}
|