2022-01-23 01:24:41 +05:30
|
|
|
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-01-17 11:32:13 +05:30
|
|
|
"github.com/authorizerdev/authorizer/server/envstore"
|
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
|
2022-03-08 12:36:26 +05:30
|
|
|
func CreateVerificationToken(email, tokenType, hostname, nonceHash, redirectURL string) (string, error) {
|
2022-02-12 15:54:23 +05:30
|
|
|
claims := jwt.MapClaims{
|
2022-03-02 17:42:31 +05:30
|
|
|
"iss": hostname,
|
|
|
|
"aud": envstore.EnvStoreObj.GetStringStoreEnvVariable(constants.EnvKeyClientID),
|
|
|
|
"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
|
|
|
}
|