-
Notifications
You must be signed in to change notification settings - Fork 0
/
token.go
37 lines (31 loc) · 1019 Bytes
/
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
package v2
import jwt "github.com/dgrijalva/jwt-go"
// Claims represents the JWT claims
type Claims struct {
jwt.StandardClaims
// Custom claims
Groups []string `json:"groups"`
Provider AuthProviderClaims `json:"provider"`
}
// AuthProviderClaims contains information from the authentication provider
type AuthProviderClaims struct {
// ProviderID used to login the user
ProviderID string `json:"provider_id"`
// UserID assigned to the user by the provider
UserID string `json:"user_id"`
}
// FixtureClaims returns a testing fixture for a JWT claims
func FixtureClaims(username string, groups []string) *Claims {
return &Claims{
StandardClaims: jwt.StandardClaims{Subject: username},
Groups: groups,
Provider: AuthProviderClaims{
ProviderID: "basic/default",
UserID: username,
},
}
}
// StandardClaims returns an initialized jwt.StandardClaims with the subject
func StandardClaims(subject string) jwt.StandardClaims {
return jwt.StandardClaims{Subject: subject}
}