mirror of
https://github.com/casdoor/casdoor.git
synced 2025-05-23 18:54:03 +08:00
fix: Add distinctions between access_token and refresh_token (#1280)
This commit is contained in:
parent
262aeba7e2
commit
462a82a3d5
@ -24,6 +24,7 @@ import (
|
|||||||
|
|
||||||
type Claims struct {
|
type Claims struct {
|
||||||
*User
|
*User
|
||||||
|
TokenType string `json:"tokenType,omitempty"`
|
||||||
Nonce string `json:"nonce,omitempty"`
|
Nonce string `json:"nonce,omitempty"`
|
||||||
Tag string `json:"tag,omitempty"`
|
Tag string `json:"tag,omitempty"`
|
||||||
Scope string `json:"scope,omitempty"`
|
Scope string `json:"scope,omitempty"`
|
||||||
@ -37,6 +38,7 @@ type UserShort struct {
|
|||||||
|
|
||||||
type ClaimsShort struct {
|
type ClaimsShort struct {
|
||||||
*UserShort
|
*UserShort
|
||||||
|
TokenType string `json:"tokenType,omitempty"`
|
||||||
Nonce string `json:"nonce,omitempty"`
|
Nonce string `json:"nonce,omitempty"`
|
||||||
Scope string `json:"scope,omitempty"`
|
Scope string `json:"scope,omitempty"`
|
||||||
jwt.RegisteredClaims
|
jwt.RegisteredClaims
|
||||||
@ -53,6 +55,7 @@ func getShortUser(user *User) *UserShort {
|
|||||||
func getShortClaims(claims Claims) ClaimsShort {
|
func getShortClaims(claims Claims) ClaimsShort {
|
||||||
res := ClaimsShort{
|
res := ClaimsShort{
|
||||||
UserShort: getShortUser(claims.User),
|
UserShort: getShortUser(claims.User),
|
||||||
|
TokenType: claims.TokenType,
|
||||||
Nonce: claims.Nonce,
|
Nonce: claims.Nonce,
|
||||||
Scope: claims.Scope,
|
Scope: claims.Scope,
|
||||||
RegisteredClaims: claims.RegisteredClaims,
|
RegisteredClaims: claims.RegisteredClaims,
|
||||||
@ -73,6 +76,7 @@ func generateJwtToken(application *Application, user *User, nonce string, scope
|
|||||||
|
|
||||||
claims := Claims{
|
claims := Claims{
|
||||||
User: user,
|
User: user,
|
||||||
|
TokenType: "access-token",
|
||||||
Nonce: nonce,
|
Nonce: nonce,
|
||||||
// FIXME: A workaround for custom claim by reusing `tag` in user info
|
// FIXME: A workaround for custom claim by reusing `tag` in user info
|
||||||
Tag: user.Tag,
|
Tag: user.Tag,
|
||||||
@ -97,10 +101,12 @@ func generateJwtToken(application *Application, user *User, nonce string, scope
|
|||||||
|
|
||||||
token = jwt.NewWithClaims(jwt.SigningMethodRS256, claimsShort)
|
token = jwt.NewWithClaims(jwt.SigningMethodRS256, claimsShort)
|
||||||
claimsShort.ExpiresAt = jwt.NewNumericDate(refreshExpireTime)
|
claimsShort.ExpiresAt = jwt.NewNumericDate(refreshExpireTime)
|
||||||
|
claimsShort.TokenType = "refresh-token"
|
||||||
refreshToken = jwt.NewWithClaims(jwt.SigningMethodRS256, claimsShort)
|
refreshToken = jwt.NewWithClaims(jwt.SigningMethodRS256, claimsShort)
|
||||||
} else {
|
} else {
|
||||||
token = jwt.NewWithClaims(jwt.SigningMethodRS256, claims)
|
token = jwt.NewWithClaims(jwt.SigningMethodRS256, claims)
|
||||||
claims.ExpiresAt = jwt.NewNumericDate(refreshExpireTime)
|
claims.ExpiresAt = jwt.NewNumericDate(refreshExpireTime)
|
||||||
|
claims.TokenType = "refresh-token"
|
||||||
refreshToken = jwt.NewWithClaims(jwt.SigningMethodRS256, claims)
|
refreshToken = jwt.NewWithClaims(jwt.SigningMethodRS256, claims)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user