mirror of
https://github.com/casdoor/casdoor.git
synced 2025-05-23 02:35:49 +08:00
feat: add email_verified, phone_number and phone_number_verified field for standard jwt token (#3156)
* feat: add email_verified, phone_number and phone_number_verified field for standard jwt token * fix: fix linter err
This commit is contained in:
parent
ec98785172
commit
9b33800b4c
@ -18,16 +18,20 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/casdoor/casdoor/util"
|
||||||
"github.com/golang-jwt/jwt/v4"
|
"github.com/golang-jwt/jwt/v4"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ClaimsStandard struct {
|
type ClaimsStandard struct {
|
||||||
*UserShort
|
*UserShort
|
||||||
Gender string `json:"gender,omitempty"`
|
EmailVerified bool `json:"email_verified,omitempty"`
|
||||||
TokenType string `json:"tokenType,omitempty"`
|
PhoneNumber string `json:"phone_number,omitempty"`
|
||||||
Nonce string `json:"nonce,omitempty"`
|
PhoneNumberVerified bool `json:"phone_number_verified,omitempty"`
|
||||||
Scope string `json:"scope,omitempty"`
|
Gender string `json:"gender,omitempty"`
|
||||||
Address OIDCAddress `json:"address,omitempty"`
|
TokenType string `json:"tokenType,omitempty"`
|
||||||
|
Nonce string `json:"nonce,omitempty"`
|
||||||
|
Scope string `json:"scope,omitempty"`
|
||||||
|
Address OIDCAddress `json:"address,omitempty"`
|
||||||
|
|
||||||
jwt.RegisteredClaims
|
jwt.RegisteredClaims
|
||||||
}
|
}
|
||||||
@ -43,12 +47,14 @@ func getStreetAddress(user *User) string {
|
|||||||
func getStandardClaims(claims Claims) ClaimsStandard {
|
func getStandardClaims(claims Claims) ClaimsStandard {
|
||||||
res := ClaimsStandard{
|
res := ClaimsStandard{
|
||||||
UserShort: getShortUser(claims.User),
|
UserShort: getShortUser(claims.User),
|
||||||
|
EmailVerified: claims.User.EmailVerified,
|
||||||
TokenType: claims.TokenType,
|
TokenType: claims.TokenType,
|
||||||
Nonce: claims.Nonce,
|
Nonce: claims.Nonce,
|
||||||
Scope: claims.Scope,
|
Scope: claims.Scope,
|
||||||
RegisteredClaims: claims.RegisteredClaims,
|
RegisteredClaims: claims.RegisteredClaims,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
res.Phone = ""
|
||||||
var scopes []string
|
var scopes []string
|
||||||
|
|
||||||
if strings.Contains(claims.Scope, ",") {
|
if strings.Contains(claims.Scope, ",") {
|
||||||
@ -62,6 +68,15 @@ func getStandardClaims(claims Claims) ClaimsStandard {
|
|||||||
res.Address = OIDCAddress{StreetAddress: getStreetAddress(claims.User)}
|
res.Address = OIDCAddress{StreetAddress: getStreetAddress(claims.User)}
|
||||||
} else if scope == "profile" {
|
} else if scope == "profile" {
|
||||||
res.Gender = claims.User.Gender
|
res.Gender = claims.User.Gender
|
||||||
|
} else if scope == "phone" && claims.User.Phone != "" {
|
||||||
|
res.PhoneNumberVerified = true
|
||||||
|
phoneNumber, ok := util.GetE164Number(claims.User.Phone, claims.User.CountryCode)
|
||||||
|
if !ok {
|
||||||
|
res.PhoneNumberVerified = false
|
||||||
|
} else {
|
||||||
|
res.PhoneNumber = phoneNumber
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user