feat: add api for admin login
This commit is contained in:
@@ -124,3 +124,31 @@ func VerifyAuthToken(token string) (map[string]interface{}, error) {
|
||||
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func CreateAdminAuthToken(tokenType enum.TokenType, c *gin.Context) (string, int64, error) {
|
||||
t := jwt.New(jwt.GetSigningMethod(constants.JWT_TYPE))
|
||||
expiryBound := time.Hour
|
||||
if tokenType == enum.RefreshToken {
|
||||
// expires in 1 year
|
||||
expiryBound = time.Hour * 8760
|
||||
}
|
||||
|
||||
expiresAt := time.Now().Add(expiryBound).Unix()
|
||||
|
||||
customClaims := jwt.MapClaims{
|
||||
"exp": expiresAt,
|
||||
"iat": time.Now().Unix(),
|
||||
"user_agent": GetUserAgent(c.Request),
|
||||
"ip": GetIP(c.Request),
|
||||
"role": "authorizer_admin",
|
||||
"created_at": time.Now().Unix(),
|
||||
}
|
||||
|
||||
t.Claims = customClaims
|
||||
|
||||
token, err := t.SignedString([]byte(constants.JWT_SECRET))
|
||||
if err != nil {
|
||||
return "", 0, err
|
||||
}
|
||||
return token, expiresAt, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user