Add test for jwt tokens

This commit is contained in:
Lakhan Samani
2022-02-12 19:26:37 +05:30
parent 8259fb515c
commit 1f058f954d
2 changed files with 150 additions and 1 deletions

View File

@@ -12,7 +12,13 @@ import (
func SignJWTToken(claims jwt.MapClaims) (string, error) {
jwtType := envstore.EnvInMemoryStoreObj.GetStringStoreEnvVariable(constants.EnvKeyJwtType)
signingMethod := jwt.GetSigningMethod(jwtType)
if signingMethod == nil {
return "", errors.New("unsupported signing method")
}
t := jwt.New(signingMethod)
if t == nil {
return "", errors.New("unsupported signing method")
}
t.Claims = claims
switch signingMethod {
@@ -45,7 +51,7 @@ func ParseJWTToken(token string) (jwt.MapClaims, error) {
switch signingMethod {
case jwt.SigningMethodHS256, jwt.SigningMethodHS384, jwt.SigningMethodHS512:
_, err = jwt.ParseWithClaims(token, claims, func(token *jwt.Token) (interface{}, error) {
_, err = jwt.ParseWithClaims(token, &claims, func(token *jwt.Token) (interface{}, error) {
return []byte(envstore.EnvInMemoryStoreObj.GetStringStoreEnvVariable(constants.EnvKeyJwtSecret)), nil
})
case jwt.SigningMethodRS256, jwt.SigningMethodRS384, jwt.SigningMethodRS512: