-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcognito-checker.go
37 lines (30 loc) · 985 Bytes
/
cognito-checker.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 gojwtcognito
import (
"fmt"
"github.com/lestrrat-go/jwx/jwk"
)
// CognitoChecker is the main object of the API of the package.
// Contains information about your AWS Cognito configuration.
type CognitoChecker struct {
region string
userPool string
appClient string
jwks *jwk.Set
}
// NewCognitoChecker is used for generating a CognitoChecker object and been able to use the library
// Needs the region, user pool id and app client id of your Cognito user pool to work properly
func NewCognitoChecker(region, userPool, appClient string) (*CognitoChecker, error) {
cognitoChecker := &CognitoChecker{}
cognitoChecker.region = region
cognitoChecker.userPool = userPool
cognitoChecker.appClient = appClient
jwkURL := fmt.Sprintf("https://cognito-idp.%v.amazonaws.com/%v/.well-known/jwks.json",
region,
userPool)
jwks, err := jwk.Fetch(jwkURL)
if err != nil {
return cognitoChecker, err
}
cognitoChecker.jwks = jwks
return cognitoChecker, nil
}