Skip to content

Commit

Permalink
feat: expand on Principal attributes + improve PrincipalFromContext
Browse files Browse the repository at this point in the history
  • Loading branch information
BarcoMasile committed Jun 28, 2024
1 parent f6e8277 commit 4104b3a
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions pkg/authentication/oidc.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,15 @@ var (
)

type Principal struct {
Subject string `json:"sub"`
Nonce string `json:"nonce"`
Subject string `json:"sub"`
Name string `json:"name"`
Email string `json:"email"`
SessionID string `json:"sid"`
Nonce string `json:"nonce"`

RawAccessToken string `json:"-"`
RawIdToken string `json:"-"`
RawRefreshToken string `json:"-"`
}

func NewPrincipalFromClaims(c ReadableClaims) (*Principal, error) {
Expand All @@ -50,7 +57,12 @@ func PrincipalFromContext(ctx context.Context) *Principal {
return nil
}

return ctx.Value(PrincipalContextKey).(*Principal)
value := ctx.Value(PrincipalContextKey)
if value == nil {
return nil
}

return value.(*Principal)
}

func OtelHTTPClientContext(ctx context.Context) context.Context {
Expand Down

0 comments on commit 4104b3a

Please sign in to comment.