-
Notifications
You must be signed in to change notification settings - Fork 0
/
jwt.go
63 lines (48 loc) · 996 Bytes
/
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
package main
import (
"crypto/rsa"
"crypto/tls"
soffit "astuart.co/soffit-go"
"github.com/dgrijalva/jwt-go"
)
const (
jIss = "soffit-go.test.astuart.co"
jAud = "portal.astuart.co"
kid = "soffit-signer"
)
const (
KeySize = 1 << 12
)
var (
signingKey *rsa.PrivateKey
tlsCert *tls.Certificate
)
func init() {
// k, err := rsa.GenerateKey(rand.Reader, KeySize)
// if err != nil {
// log.Fatal(err)
// }
// signingKey = k
// bs, err := x509.MarshalPKIXPublicKey(&k.PublicKey)
// if err != nil {
// log.Fatal(err)
// }
// p := &pem.Block{
// Bytes: bs,
// Type: "PUBLIC KEY",
// }
// log.Println("Public Key:")
// pem.Encode(os.Stdout, p)
}
func getJWT(req soffit.Payload, secret string) (string, error) {
t := jwt.New(jwt.SigningMethodRS256)
t.Header["kid"] = kid
t.Claims = jwt.MapClaims{
"iss": jIss,
"aud": jAud,
"sub": req.User.Username,
"org.apereo.portal.soffitRequest": req,
"secret": secret,
}
return t.SignedString(signingKey)
}