mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-03 20:50:19 +08:00
feat: add OIDC feature support. (#373)
1. add nonce parameter. 2. add sub in userinfo endpoint. Signed-off-by: 0x2a <stevesough@gmail.com>
This commit is contained in:
@ -175,7 +175,7 @@ func CheckOAuthLogin(clientId string, responseType string, redirectUri string, s
|
||||
return "", application
|
||||
}
|
||||
|
||||
func GetOAuthCode(userId string, clientId string, responseType string, redirectUri string, scope string, state string) *Code {
|
||||
func GetOAuthCode(userId string, clientId string, responseType string, redirectUri string, scope string, state string, nonce string) *Code {
|
||||
user := GetUser(userId)
|
||||
if user == nil {
|
||||
return &Code{
|
||||
@ -192,7 +192,7 @@ func GetOAuthCode(userId string, clientId string, responseType string, redirectU
|
||||
}
|
||||
}
|
||||
|
||||
accessToken, err := generateJwtToken(application, user)
|
||||
accessToken, err := generateJwtToken(application, user, nonce)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
@ -31,17 +31,19 @@ var tokenJwtPrivateKey string
|
||||
|
||||
type Claims struct {
|
||||
User
|
||||
Nonce string `json:"nonce,omitempty"`
|
||||
jwt.RegisteredClaims
|
||||
}
|
||||
|
||||
func generateJwtToken(application *Application, user *User) (string, error) {
|
||||
func generateJwtToken(application *Application, user *User, nonce string) (string, error) {
|
||||
nowTime := time.Now()
|
||||
expireTime := nowTime.Add(time.Duration(application.ExpireInHours) * time.Hour)
|
||||
|
||||
user.Password = ""
|
||||
|
||||
claims := Claims{
|
||||
User: *user,
|
||||
User: *user,
|
||||
Nonce: nonce,
|
||||
RegisteredClaims: jwt.RegisteredClaims{
|
||||
Issuer: beego.AppConfig.String("origin"),
|
||||
Subject: user.Id,
|
||||
|
Reference in New Issue
Block a user