This repository has been archived by the owner on Apr 9, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathjwt.go
85 lines (72 loc) · 2.83 KB
/
jwt.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package stormpath
import (
"gopkg.in/dgrijalva/jwt-go.v3"
)
//SSOTokenClaims are the JWT for initiating an IDSite workflow
//
//see: http://docs.stormpath.com/guides/using-id-site/
type SSOTokenClaims struct {
jwt.StandardClaims
CallbackURI string `json:"cb_uri,omitempty"`
Path string `json:"path,omitempty"`
State string `json:"state,omitempty"`
OrganizationNameKey string `json:"organizationNameKey,omitempty"`
ShowOrganiztaionField bool `json:"showOrganiztaionField,omitempty"`
}
//IDSiteAssertionTokenClaims are the JWT claims of an Stormpath Assertion type authentication
//this could originage from an IDSite workflow
type IDSiteAssertionTokenClaims struct {
jwt.StandardClaims
State string `json:"state,omitempty"`
Status string `json:"status,omitempty"`
}
//SAMLAssertionTokenClaims are the JWT claims of an Stormpath Assertion type authentication
//this could originage from an SAML workflow
type SAMLAssertionTokenClaims struct {
jwt.StandardClaims
State string `json:"state,omitempty"`
Status string `json:"status,omitempty"`
IsNewSub string `json:"isNewSub,omitempty"`
IRT string `json:"irt,omitempty"`
}
//SAMLAuthenticationTokenClaims are the JWT claims needed to start a Stormpath SAML workflow
type SAMLAuthenticationTokenClaims struct {
jwt.StandardClaims
CallbackURI string `json:"cb_uri,omitempty"`
State string `json:"state,omitempty"`
ASH string `json:"ash,omitempty"`
ONK string `json:"onk,omitempty"`
}
//GrantTypeStormpathTokenClaims are the JWT claims for a Stormpath OAuth2 authentication using
//the stormpath_token grant type
type GrantTypeStormpathTokenClaims struct {
jwt.StandardClaims
Status string `json:"status,omitempty"`
}
//GrantTypeClientCredentialsTokenClaims are the JWT claims use for the client credentials OAuth2 grant type
//authentication
type GrantTypeClientCredentialsTokenClaims struct {
jwt.StandardClaims
Scope string `json:"scope,omitempty"`
}
//AccessTokenClaims are the JWT for a Stormpath OAuth2 access token
type AccessTokenClaims struct {
jwt.StandardClaims
RefreshTokenID string `json:"rti,omitempty"`
}
//JWT helper function to create JWT token strings with the given claims, extra header values,
//and sign with client API Key Secret using SigningMethodHS256 algorithm
func JWT(claims jwt.Claims, extraHeaders map[string]interface{}) string {
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
for key, value := range extraHeaders {
token.Header[key] = value
}
encodedJWT, _ := token.SignedString(client.ClientConfiguration.GetJWTSigningKey())
return encodedJWT
}
func ParseJWT(token string, claims jwt.Claims) *jwt.Token {
decodedJWT, _ := jwt.ParseWithClaims(token, claims, func(token *jwt.Token) (interface{}, error) {
return client.ClientConfiguration.GetJWTSigningKey(), nil
})
return decodedJWT
}