authorizer/server/token/verification_token.go

26 lines
733 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-01-17 06:02:13 +00:00
"github.com/authorizerdev/authorizer/server/envstore"
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) {
2022-02-12 10:24:23 +00:00
claims := jwt.MapClaims{
2022-03-02 12:12:31 +00:00
"iss": hostname,
"aud": envstore.EnvStoreObj.GetStringStoreEnvVariable(constants.EnvKeyClientID),
"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,
"redirect_url": 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
}