-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclaims.go
63 lines (57 loc) · 2.09 KB
/
claims.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package oidc
import (
"encoding/json"
)
// https://openid.net/specs/openid-connect-core-1_0.html#StandardClaims.
type StandardClaims struct {
Address *Address `json:"address,omitempty"`
Birthdate string `json:"birthdate,omitempty"`
Email string `json:"email,omitempty"`
EmailVerified bool `json:"email_verified,omitempty"`
FamilyName string `json:"family_name,omitempty"`
Gender string `json:"gender,omitempty"`
GivenName string `json:"given_name,omitempty"`
Locale string `json:"locale,omitempty"`
MiddleName string `json:"middle_name,omitempty"`
Name string `json:"name,omitempty"`
Nickname string `json:"nickname,omitempty"`
PhoneNumber string `json:"phone_number,omitempty"`
PhoneNumberVerified bool `json:"phone_number_verified,omitempty"`
Picture string `json:"picture,omitempty"`
PreferredUsername string `json:"preferred_username,omitempty"`
Profile string `json:"profile,omitempty"`
Subject string `json:"sub,omitempty"`
UpdatedAt int64 `json:"updated_at,omitempty"`
Website string `json:"website,omitempty"`
ZoneInfo string `json:"zoneinfo,omitempty"`
}
// https://openid.net/specs/openid-connect-core-1_0.html#Address.
type Address struct {
Country string `json:"country,omitempty"`
Formatted string `json:"formatted,omitempty"`
Locality string `json:"locality,omitempty"`
PostalCode string `json:"postal_code,omitempty"`
Region string `json:"region,omitempty"`
StreetAddress string `json:"street_address,omitempty"`
}
type Claims struct {
StandardClaims
All map[string]any
}
func (c *Claims) UnmarshalJSON(b []byte) (err error) {
if err = json.Unmarshal(b, &c.StandardClaims); err != nil {
return
}
if err = json.Unmarshal(b, &c.All); err != nil {
return
}
return
}
func (c *Claims) GetString(key string) string {
if val, ok := c.All[key]; ok {
if str, ok := val.(string); ok {
return str
}
}
return ""
}