feat(server): add allowed_roles in access_token + refresh_token

This commit is contained in:
Lakhan Samani 2022-11-07 07:11:23 +05:30
parent 307c6f7d15
commit 4afd544c41

View File

@ -114,16 +114,17 @@ func CreateRefreshToken(user models.User, roles, scopes []string, hostname, nonc
return "", 0, err return "", 0, err
} }
customClaims := jwt.MapClaims{ customClaims := jwt.MapClaims{
"iss": hostname, "iss": hostname,
"aud": clientID, "aud": clientID,
"sub": user.ID, "sub": user.ID,
"exp": expiresAt, "exp": expiresAt,
"iat": time.Now().Unix(), "iat": time.Now().Unix(),
"token_type": constants.TokenTypeRefreshToken, "token_type": constants.TokenTypeRefreshToken,
"roles": roles, "roles": roles,
"scope": scopes, "scope": scopes,
"nonce": nonce, "nonce": nonce,
"login_method": loginMethod, "login_method": loginMethod,
"allowed_roles": strings.Split(user.Roles, ","),
} }
token, err := SignJWTToken(customClaims) token, err := SignJWTToken(customClaims)
@ -153,16 +154,17 @@ func CreateAccessToken(user models.User, roles, scopes []string, hostName, nonce
return "", 0, err return "", 0, err
} }
customClaims := jwt.MapClaims{ customClaims := jwt.MapClaims{
"iss": hostName, "iss": hostName,
"aud": clientID, "aud": clientID,
"nonce": nonce, "nonce": nonce,
"sub": user.ID, "sub": user.ID,
"exp": expiresAt, "exp": expiresAt,
"iat": time.Now().Unix(), "iat": time.Now().Unix(),
"token_type": constants.TokenTypeAccessToken, "token_type": constants.TokenTypeAccessToken,
"scope": scopes, "scope": scopes,
"roles": roles, "roles": roles,
"login_method": loginMethod, "login_method": loginMethod,
"allowed_roles": strings.Split(user.Roles, ","),
} }
token, err := SignJWTToken(customClaims) token, err := SignJWTToken(customClaims)