mirror of
https://github.com/casdoor/casdoor.git
synced 2025-05-23 02:35:49 +08:00
feat: fix token info not contains roles and permissions (#1060)
* fix: fix token info not contains roles and permissions feat: remove repeated code for obtaining roles and permissions in user controller * Update user.go * Update user.go * Update token.go Co-authored-by: Yang Luo <hsluoyz@qq.com>
This commit is contained in:
parent
f02875e1b1
commit
a383af0ebc
@ -119,12 +119,7 @@ func (c *ApiController) GetUser() {
|
||||
user = object.GetUser(id)
|
||||
}
|
||||
|
||||
if user != nil {
|
||||
roles := object.GetRolesByUser(user.GetId())
|
||||
user.Roles = roles
|
||||
permissions := object.GetPermissionsByUser(user.GetId())
|
||||
user.Permissions = permissions
|
||||
}
|
||||
object.ExtendUserWithRolesAndPermissions(user)
|
||||
|
||||
c.Data["json"] = object.GetMaskedUser(user)
|
||||
c.ServeJSON()
|
||||
|
@ -287,6 +287,7 @@ func GetOAuthCode(userId string, clientId string, responseType string, redirectU
|
||||
}
|
||||
}
|
||||
|
||||
ExtendUserWithRolesAndPermissions(user)
|
||||
accessToken, refreshToken, tokenName, err := generateJwtToken(application, user, nonce, scope, host)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@ -421,6 +422,7 @@ func RefreshToken(grantType string, refreshToken string, scope string, clientId
|
||||
}
|
||||
}
|
||||
|
||||
ExtendUserWithRolesAndPermissions(user)
|
||||
newAccessToken, newRefreshToken, tokenName, err := generateJwtToken(application, user, "", scope, host)
|
||||
if err != nil {
|
||||
return &TokenError{
|
||||
@ -571,6 +573,7 @@ func GetPasswordToken(application *Application, username string, password string
|
||||
}
|
||||
}
|
||||
|
||||
ExtendUserWithRolesAndPermissions(user)
|
||||
accessToken, refreshToken, tokenName, err := generateJwtToken(application, user, "", scope, host)
|
||||
if err != nil {
|
||||
return nil, &TokenError{
|
||||
@ -640,6 +643,7 @@ func GetClientCredentialsToken(application *Application, clientSecret string, sc
|
||||
// GetTokenByUser
|
||||
// Implicit flow
|
||||
func GetTokenByUser(application *Application, user *User, scope string, host string) (*Token, error) {
|
||||
ExtendUserWithRolesAndPermissions(user)
|
||||
accessToken, refreshToken, tokenName, err := generateJwtToken(application, user, "", scope, host)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -726,6 +730,7 @@ func GetWechatMiniProgramToken(application *Application, code string, host strin
|
||||
AddUser(user)
|
||||
}
|
||||
|
||||
ExtendUserWithRolesAndPermissions(user)
|
||||
accessToken, refreshToken, tokenName, err := generateJwtToken(application, user, "", "", host)
|
||||
if err != nil {
|
||||
return nil, &TokenError{
|
||||
|
@ -566,3 +566,12 @@ func (user *User) GetId() string {
|
||||
func isUserIdGlobalAdmin(userId string) bool {
|
||||
return strings.HasPrefix(userId, "built-in/")
|
||||
}
|
||||
|
||||
func ExtendUserWithRolesAndPermissions(user *User) {
|
||||
if user == nil {
|
||||
return
|
||||
}
|
||||
|
||||
user.Roles = GetRolesByUser(user.GetId())
|
||||
user.Permissions = GetPermissionsByUser(user.GetId())
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user