Debian Codegraph @

internal/oauth2/idtoken/main.go

raw
1 package idtoken
2
3 import (
4 "encoding/json"
5 "fmt"
6
7 "github.com/zitadel/oidc/v3/pkg/oidc"
8 )
9
10 type IDToken = oidc.Tokens[*Claims]
11
12 //nolint:tagliatelle
13 type Claims struct {
14 oidc.TokenClaims
15
16 Claims map[string]any `json:"-"`
17
18 PreferredUsername string `json:"preferred_username,omitempty"`
19 AccessTokenHash string `json:"at_hash,omitempty"`
20 IPAddr string `json:"ipaddr,omitempty"`
21 EMail string `json:"email,omitempty"`
22 }
23
24 // GetAccessTokenHash implements the oidc.IDTokenClaims interface.
25 func (c *Claims) GetAccessTokenHash() string {
26 return c.AccessTokenHash
27 }
28
29 type cAlias Claims
30
31 // UnmarshalJSON decodes both typed ID token claims and the raw claims map.
32 func (c *Claims) UnmarshalJSON(data []byte) error {
33 if err := json.Unmarshal(data, (*cAlias)(c)); err != nil {
34 return fmt.Errorf("claims: %w into %T", err, c)
35 }
36
37 if err := json.Unmarshal(data, &c.Claims); err != nil {
38 return fmt.Errorf("claims: %w into %T", err, &c.Claims)
39 }
40
41 return nil
42 }