mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-04 13:20:19 +08:00
feat: end-user log out (#1356)
This commit is contained in:
@ -40,6 +40,7 @@ type OidcDiscovery struct {
|
||||
ClaimsSupported []string `json:"claims_supported"`
|
||||
RequestParameterSupported bool `json:"request_parameter_supported"`
|
||||
RequestObjectSigningAlgValuesSupported []string `json:"request_object_signing_alg_values_supported"`
|
||||
EndSessionEndpoint string `json:"end_session_endpoint"`
|
||||
}
|
||||
|
||||
func getOriginFromHost(host string) (string, string) {
|
||||
@ -84,6 +85,7 @@ func GetOidcDiscovery(host string) OidcDiscovery {
|
||||
ClaimsSupported: []string{"iss", "ver", "sub", "aud", "iat", "exp", "id", "type", "displayName", "avatar", "permanentAvatar", "email", "phone", "location", "affiliation", "title", "homepage", "bio", "tag", "region", "language", "score", "ranking", "isOnline", "isAdmin", "isGlobalAdmin", "isForbidden", "signupApplication", "ldap"},
|
||||
RequestParameterSupported: true,
|
||||
RequestObjectSigningAlgValuesSupported: []string{"HS256", "HS384", "HS512"},
|
||||
EndSessionEndpoint: fmt.Sprintf("%s/api/logout", originBackend),
|
||||
}
|
||||
|
||||
return oidcDiscovery
|
||||
|
@ -15,8 +15,6 @@
|
||||
package object
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/beego/beego"
|
||||
"github.com/casdoor/casdoor/util"
|
||||
"xorm.io/core"
|
||||
@ -42,7 +40,7 @@ func SetSession(id string, sessionId string) {
|
||||
if get {
|
||||
_, err = adapter.Engine.ID(core.PK{owner, name}).Update(session)
|
||||
} else {
|
||||
session.CreatedTime = time.Now().Format(time.RFC3339)
|
||||
session.CreatedTime = util.GetCurrentTime()
|
||||
_, err = adapter.Engine.Insert(session)
|
||||
}
|
||||
if err != nil {
|
||||
@ -66,7 +64,7 @@ func DeleteSession(id string) bool {
|
||||
}
|
||||
|
||||
func DeleteSessionId(id string, sessionId string) bool {
|
||||
owner, name := util.GetOwnerAndNameFromIdNoCheck(id)
|
||||
owner, name := util.GetOwnerAndNameFromId(id)
|
||||
|
||||
session := &Session{Owner: owner, Name: name}
|
||||
_, err := adapter.Engine.ID(core.PK{owner, name}).Get(session)
|
||||
|
@ -27,7 +27,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
hourSeconds = 3600
|
||||
hourMinutes = 60
|
||||
InvalidRequest = "invalid_request"
|
||||
InvalidClient = "invalid_client"
|
||||
InvalidGrant = "invalid_grant"
|
||||
@ -204,7 +204,7 @@ func DeleteToken(token *Token) bool {
|
||||
return affected != 0
|
||||
}
|
||||
|
||||
func DeleteTokenByAccessToken(accessToken string) (bool, *Application) {
|
||||
func ExpireTokenByAccessToken(accessToken string) (bool, *Application, *Token) {
|
||||
token := Token{AccessToken: accessToken}
|
||||
existed, err := adapter.Engine.Get(&token)
|
||||
if err != nil {
|
||||
@ -212,15 +212,17 @@ func DeleteTokenByAccessToken(accessToken string) (bool, *Application) {
|
||||
}
|
||||
|
||||
if !existed {
|
||||
return false, nil
|
||||
return false, nil, nil
|
||||
}
|
||||
application := getApplication(token.Owner, token.Application)
|
||||
affected, err := adapter.Engine.Where("access_token=?", accessToken).Delete(&Token{})
|
||||
|
||||
token.ExpiresIn = 0
|
||||
affected, err := adapter.Engine.ID(core.PK{token.Owner, token.Name}).Cols("expires_in").Update(&token)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return affected != 0, application
|
||||
application := getApplication(token.Owner, token.Application)
|
||||
return affected != 0, application, &token
|
||||
}
|
||||
|
||||
func GetTokenByAccessToken(accessToken string) *Token {
|
||||
@ -304,7 +306,7 @@ func GetOAuthCode(userId string, clientId string, responseType string, redirectU
|
||||
Code: util.GenerateClientId(),
|
||||
AccessToken: accessToken,
|
||||
RefreshToken: refreshToken,
|
||||
ExpiresIn: application.ExpireInHours * hourSeconds,
|
||||
ExpiresIn: application.ExpireInHours * hourMinutes,
|
||||
Scope: scope,
|
||||
TokenType: "Bearer",
|
||||
CodeChallenge: challenge,
|
||||
@ -438,7 +440,7 @@ func RefreshToken(grantType string, refreshToken string, scope string, clientId
|
||||
Code: util.GenerateClientId(),
|
||||
AccessToken: newAccessToken,
|
||||
RefreshToken: newRefreshToken,
|
||||
ExpiresIn: application.ExpireInHours * hourSeconds,
|
||||
ExpiresIn: application.ExpireInHours * hourMinutes,
|
||||
Scope: scope,
|
||||
TokenType: "Bearer",
|
||||
}
|
||||
@ -588,7 +590,7 @@ func GetPasswordToken(application *Application, username string, password string
|
||||
Code: util.GenerateClientId(),
|
||||
AccessToken: accessToken,
|
||||
RefreshToken: refreshToken,
|
||||
ExpiresIn: application.ExpireInHours * hourSeconds,
|
||||
ExpiresIn: application.ExpireInHours * hourMinutes,
|
||||
Scope: scope,
|
||||
TokenType: "Bearer",
|
||||
CodeIsUsed: true,
|
||||
@ -628,7 +630,7 @@ func GetClientCredentialsToken(application *Application, clientSecret string, sc
|
||||
User: nullUser.Name,
|
||||
Code: util.GenerateClientId(),
|
||||
AccessToken: accessToken,
|
||||
ExpiresIn: application.ExpireInHours * hourSeconds,
|
||||
ExpiresIn: application.ExpireInHours * hourMinutes,
|
||||
Scope: scope,
|
||||
TokenType: "Bearer",
|
||||
CodeIsUsed: true,
|
||||
@ -655,7 +657,7 @@ func GetTokenByUser(application *Application, user *User, scope string, host str
|
||||
Code: util.GenerateClientId(),
|
||||
AccessToken: accessToken,
|
||||
RefreshToken: refreshToken,
|
||||
ExpiresIn: application.ExpireInHours * hourSeconds,
|
||||
ExpiresIn: application.ExpireInHours * hourMinutes,
|
||||
Scope: scope,
|
||||
TokenType: "Bearer",
|
||||
CodeIsUsed: true,
|
||||
|
Reference in New Issue
Block a user