mirror of
https://github.com/casdoor/casdoor.git
synced 2025-05-24 08:20:31 +08:00
fix: adjust the accessToken field (#378)
* fix: adjust the accessToken field Signed-off-by: 0x2a <stevesough@gmail.com> * fix: missing name and owner Signed-off-by: 0x2a <stevesough@gmail.com>
This commit is contained in:
parent
755d912f61
commit
00f06930ba
@ -30,7 +30,9 @@ var tokenJwtPublicKey string
|
|||||||
var tokenJwtPrivateKey string
|
var tokenJwtPrivateKey string
|
||||||
|
|
||||||
type Claims struct {
|
type Claims struct {
|
||||||
User
|
*User
|
||||||
|
Name string `json:"name,omitempty"`
|
||||||
|
Owner string `json:"owner,omitempty"`
|
||||||
Nonce string `json:"nonce,omitempty"`
|
Nonce string `json:"nonce,omitempty"`
|
||||||
jwt.RegisteredClaims
|
jwt.RegisteredClaims
|
||||||
}
|
}
|
||||||
@ -43,7 +45,7 @@ func generateJwtToken(application *Application, user *User, nonce string) (strin
|
|||||||
user.Password = ""
|
user.Password = ""
|
||||||
|
|
||||||
claims := Claims{
|
claims := Claims{
|
||||||
User: *user,
|
User: user,
|
||||||
Nonce: nonce,
|
Nonce: nonce,
|
||||||
RegisteredClaims: jwt.RegisteredClaims{
|
RegisteredClaims: jwt.RegisteredClaims{
|
||||||
Issuer: beego.AppConfig.String("origin"),
|
Issuer: beego.AppConfig.String("origin"),
|
||||||
@ -55,10 +57,12 @@ func generateJwtToken(application *Application, user *User, nonce string) (strin
|
|||||||
ID: "",
|
ID: "",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
//all fields of the User struct are not added in "JWT-Empty" format
|
||||||
if application.TokenFormat == "JWT-Empty" {
|
if application.TokenFormat == "JWT-Empty" {
|
||||||
claims.User = User{}
|
claims.User = nil
|
||||||
}
|
}
|
||||||
|
claims.Name = user.Name
|
||||||
|
claims.Owner = user.Owner
|
||||||
|
|
||||||
token := jwt.NewWithClaims(jwt.SigningMethodRS256, claims)
|
token := jwt.NewWithClaims(jwt.SigningMethodRS256, claims)
|
||||||
claims.ExpiresAt = jwt.NewNumericDate(refreshExpireTime)
|
claims.ExpiresAt = jwt.NewNumericDate(refreshExpireTime)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user