Files
authorizer/server/token/verification_token.go

30 lines
800 B
Go
Raw Normal View History

package token
2021-07-12 23:52:16 +05:30
import (
"time"
2021-07-23 21:57:44 +05:30
"github.com/authorizerdev/authorizer/server/constants"
2022-05-30 09:19:55 +05:30
"github.com/authorizerdev/authorizer/server/memorystore"
2021-07-12 23:52:16 +05:30
"github.com/golang-jwt/jwt"
)
2022-01-17 11:32:13 +05:30
// 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 15:54:23 +05:30
claims := jwt.MapClaims{
2022-03-02 17:42:31 +05:30
"iss": hostname,
"aud": clientID,
2022-03-02 17:42:31 +05:30
"sub": email,
2022-02-12 15:54:23 +05:30
"exp": time.Now().Add(time.Minute * 30).Unix(),
"iat": time.Now().Unix(),
"token_type": tokenType,
2022-03-02 17:42:31 +05:30
"nonce": nonceHash,
2022-03-08 22:41:33 +05:30
"redirect_uri": redirectURL,
2021-07-12 23:52:16 +05:30
}
2022-02-12 15:54:23 +05:30
return SignJWTToken(claims)
2021-07-12 23:52:16 +05:30
}