authorizer/server/token/verification_token.go

30 lines
800 B
Go
Raw Normal View History

package token
2021-07-12 18:22:16 +00:00
import (
"time"
2021-07-23 16:27:44 +00:00
"github.com/authorizerdev/authorizer/server/constants"
2022-05-30 03:49:55 +00:00
"github.com/authorizerdev/authorizer/server/memorystore"
2021-07-12 18:22:16 +00:00
"github.com/golang-jwt/jwt"
)
2022-01-17 06:02:13 +00:00
// CreateVerificationToken creates a verification JWT token
func CreateVerificationToken(email, tokenType, hostname, nonceHash, redirectURL string) (string, error) {
clientID, err := memorystore.Provider.GetStringStoreEnvVariable(constants.EnvKeyClientID)
if err != nil {
return "", err
}
2022-02-12 10:24:23 +00:00
claims := jwt.MapClaims{
2022-03-02 12:12:31 +00:00
"iss": hostname,
"aud": clientID,
2022-03-02 12:12:31 +00:00
"sub": email,
2022-02-12 10:24:23 +00:00
"exp": time.Now().Add(time.Minute * 30).Unix(),
"iat": time.Now().Unix(),
"token_type": tokenType,
2022-03-02 12:12:31 +00:00
"nonce": nonceHash,
2022-03-08 17:11:33 +00:00
"redirect_uri": redirectURL,
2021-07-12 18:22:16 +00:00
}
2022-02-12 10:24:23 +00:00
return SignJWTToken(claims)
2021-07-12 18:22:16 +00:00
}