🐛 Fix id token mismatch the userinfo endpoint
All checks were successful
release-nightly / build-docker (push) Successful in 3m26s
All checks were successful
release-nightly / build-docker (push) Successful in 3m26s
This commit is contained in:
parent
39904dc08c
commit
ecda5bd59b
@ -11,8 +11,8 @@ import (
|
|||||||
type PayloadClaims struct {
|
type PayloadClaims struct {
|
||||||
jwt.RegisteredClaims
|
jwt.RegisteredClaims
|
||||||
|
|
||||||
Type string `json:"typ"`
|
SessionID string `json:"sed"`
|
||||||
Value any `json:"val"`
|
Type string `json:"typ"`
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -20,7 +20,7 @@ const (
|
|||||||
JwtRefreshType = "refresh"
|
JwtRefreshType = "refresh"
|
||||||
)
|
)
|
||||||
|
|
||||||
func EncodeJwt(id string, val any, typ, sub string, aud []string, exp time.Time) (string, error) {
|
func EncodeJwt(id string, typ, sub, sed string, aud []string, exp time.Time) (string, error) {
|
||||||
tk := jwt.NewWithClaims(jwt.SigningMethodHS512, PayloadClaims{
|
tk := jwt.NewWithClaims(jwt.SigningMethodHS512, PayloadClaims{
|
||||||
jwt.RegisteredClaims{
|
jwt.RegisteredClaims{
|
||||||
Subject: sub,
|
Subject: sub,
|
||||||
@ -31,8 +31,8 @@ func EncodeJwt(id string, val any, typ, sub string, aud []string, exp time.Time)
|
|||||||
IssuedAt: jwt.NewNumericDate(time.Now()),
|
IssuedAt: jwt.NewNumericDate(time.Now()),
|
||||||
ID: id,
|
ID: id,
|
||||||
},
|
},
|
||||||
|
sed,
|
||||||
typ,
|
typ,
|
||||||
val,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
return tk.SignedString([]byte(viper.GetString("secret")))
|
return tk.SignedString([]byte(viper.GetString("secret")))
|
||||||
|
@ -86,12 +86,13 @@ func GetToken(session models.AuthSession) (string, string, error) {
|
|||||||
|
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
sub := strconv.Itoa(int(session.ID))
|
sub := strconv.Itoa(int(session.AccountID))
|
||||||
access, err = EncodeJwt(session.AccessToken, nil, JwtAccessType, sub, session.Audiences, time.Now().Add(30*time.Minute))
|
sed := strconv.Itoa(int(session.ID))
|
||||||
|
access, err = EncodeJwt(session.AccessToken, JwtAccessType, sub, sed, session.Audiences, time.Now().Add(30*time.Minute))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return refresh, access, err
|
return refresh, access, err
|
||||||
}
|
}
|
||||||
refresh, err = EncodeJwt(session.RefreshToken, nil, JwtRefreshType, sub, session.Audiences, time.Now().Add(30*24*time.Hour))
|
refresh, err = EncodeJwt(session.RefreshToken, JwtRefreshType, sub, sed, session.Audiences, time.Now().Add(30*24*time.Hour))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return refresh, access, err
|
return refresh, access, err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user