-
Notifications
You must be signed in to change notification settings - Fork 19
/
main.go
41 lines (33 loc) · 1.07 KB
/
main.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
package main
import (
"fmt"
"github.com/kataras/jwt"
)
// |=================================================================================|
// | Amazon's AWS Cognito integration example for token validation and verification. |
// |=================================================================================|
func main() {
/*
cognitoConfig := jwt.AWSKeysConfiguration{
Region: "us-west-2",
UserPoolID: "us-west-2_xxx",
}
keys, err := cognitoConfig.Load()
if err != nil {
panic(err)
}
OR:
*/
keys, err := jwt.LoadAWSCognitoKeys("us-west-2" /* region */, "us-west-2_xxx" /* user pool id */)
if err != nil {
panic(err) // handle error, e.g. pool does not exist in the region.
}
var tokenToValidate = `xxx.xxx.xxx` // put a token here issued by your own aws cognito user pool to test it.
var claims jwt.Map // Your own custom claims here.
if err := keys.VerifyToken([]byte(tokenToValidate), &claims); err != nil {
panic(err) // handle error, e.g. token expired, or kid is empty.
}
for k, v := range claims {
fmt.Printf("%s: %v\n", k, v)
}
}