forked from dschenkelman/auth0
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon_test.go
36 lines (30 loc) · 887 Bytes
/
common_test.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
package auth0
import (
"time"
jose "gopkg.in/square/go-jose.v2"
"gopkg.in/square/go-jose.v2/jwt"
)
var (
// The default generated token by Chrome jwt extension
defaultSecret = []byte("secret")
defaultAudience = []string{"audience"}
defaultIssuer = "issuer"
defaultSecretProvider = NewKeyProvider(defaultSecret)
)
func getTestToken(audience []string, issuer string, expTime time.Time, alg jose.SignatureAlgorithm, key interface{}) string {
signer, err := jose.NewSigner(jose.SigningKey{Algorithm: alg, Key: key}, (&jose.SignerOptions{}).WithType("JWT"))
if err != nil {
panic(err)
}
cl := jwt.Claims{
Issuer: issuer,
Audience: audience,
IssuedAt: jwt.NewNumericDate(time.Now().UTC()),
Expiry: jwt.NewNumericDate(expTime),
}
raw, err := jwt.Signed(signer).Claims(cl).CompactSerialize()
if err != nil {
panic(err)
}
return raw
}