-
Notifications
You must be signed in to change notification settings - Fork 18
/
token.go
49 lines (40 loc) · 1.37 KB
/
token.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
package firebase
import "github.com/SermoDigital/jose/jwt"
// Token is a parsed read-only ID Token struct. It can be used to get the uid
// and other attributes of the user provided in the token.
type Token struct {
delegate jwt.JWT
}
// UID returns the uid for this token.
func (t *Token) UID() (string, bool) {
return t.delegate.Claims().Subject()
}
// Issuer returns the issuer for this token.
func (t *Token) Issuer() (string, bool) {
return t.delegate.Claims().Issuer()
}
// Name returns the user's display name.
func (t *Token) Name() (string, bool) {
name, ok := t.delegate.Claims().Get("name").(string)
return name, ok
}
// Picture returns the URI string of the user's profile photo.
func (t *Token) Picture() (string, bool) {
picture, ok := t.delegate.Claims().Get("picture").(string)
return picture, ok
}
// Email returns the email address for this user, or nil if it's unavailable.
func (t *Token) Email() (string, bool) {
email, ok := t.delegate.Claims().Get("email").(string)
return email, ok
}
// IsEmailVerified indicates if the email address returned by Email() has been
// verified as good.
func (t *Token) IsEmailVerified() (bool, bool) {
emailVerified, ok := t.delegate.Claims().Get("email_verified").(bool)
return emailVerified, ok
}
// Claims returns all of the claims on this token.
func (t *Token) Claims() Claims {
return Claims(t.delegate.Claims())
}