Skip to content

Commit 4afd544

Browse files
committed
feat(server): add allowed_roles in access_token + refresh_token
1 parent 307c6f7 commit 4afd544

File tree

1 file changed

+22
-20
lines changed

1 file changed

+22
-20
lines changed

server/token/auth_token.go

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -114,16 +114,17 @@ func CreateRefreshToken(user models.User, roles, scopes []string, hostname, nonc
114114
return "", 0, err
115115
}
116116
customClaims := jwt.MapClaims{
117-
"iss": hostname,
118-
"aud": clientID,
119-
"sub": user.ID,
120-
"exp": expiresAt,
121-
"iat": time.Now().Unix(),
122-
"token_type": constants.TokenTypeRefreshToken,
123-
"roles": roles,
124-
"scope": scopes,
125-
"nonce": nonce,
126-
"login_method": loginMethod,
117+
"iss": hostname,
118+
"aud": clientID,
119+
"sub": user.ID,
120+
"exp": expiresAt,
121+
"iat": time.Now().Unix(),
122+
"token_type": constants.TokenTypeRefreshToken,
123+
"roles": roles,
124+
"scope": scopes,
125+
"nonce": nonce,
126+
"login_method": loginMethod,
127+
"allowed_roles": strings.Split(user.Roles, ","),
127128
}
128129

129130
token, err := SignJWTToken(customClaims)
@@ -153,16 +154,17 @@ func CreateAccessToken(user models.User, roles, scopes []string, hostName, nonce
153154
return "", 0, err
154155
}
155156
customClaims := jwt.MapClaims{
156-
"iss": hostName,
157-
"aud": clientID,
158-
"nonce": nonce,
159-
"sub": user.ID,
160-
"exp": expiresAt,
161-
"iat": time.Now().Unix(),
162-
"token_type": constants.TokenTypeAccessToken,
163-
"scope": scopes,
164-
"roles": roles,
165-
"login_method": loginMethod,
157+
"iss": hostName,
158+
"aud": clientID,
159+
"nonce": nonce,
160+
"sub": user.ID,
161+
"exp": expiresAt,
162+
"iat": time.Now().Unix(),
163+
"token_type": constants.TokenTypeAccessToken,
164+
"scope": scopes,
165+
"roles": roles,
166+
"login_method": loginMethod,
167+
"allowed_roles": strings.Split(user.Roles, ","),
166168
}
167169

168170
token, err := SignJWTToken(customClaims)

0 commit comments

Comments
 (0)