mirror of
https://github.com/go-gitea/gitea.git
synced 2026-09-08 14:03:24 +09:00
Backport #38439 by @Otto-Deviant1904 Fixes #38209 OAuth2-linked accounts that sign in via the password form were still redirected to the provider end_session_endpoint on logout because the redirect was keyed off account LoginType. Store the session sign-in method (password vs oauth2) and only use RP-initiated OIDC logout when this session was authenticated via OAuth2. Sessions without the new key keep the previous LoginType behavior. Co-authored-by: Harsh Satyajit Thakur <f20240223@goa.bits-pilani.ac.in> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
co-authored by
Harsh Satyajit Thakur
wxiaoguang
parent
4a77fbce28
commit
0d9ce64f76
@@ -484,20 +484,26 @@ func SignOut(ctx *context.Context) {
|
||||
}
|
||||
|
||||
func buildSignOutRedirectURL(ctx *context.Context) string {
|
||||
if ctx.Doer != nil && ctx.Doer.LoginType == auth.OAuth2 {
|
||||
if ctx.Doer != nil && shouldRedirectToOIDCEndSession(ctx) {
|
||||
if s := buildOIDCEndSessionURL(ctx, ctx.Doer); s != "" {
|
||||
return s
|
||||
}
|
||||
}
|
||||
|
||||
// The assumption is: if reverse proxy auth is enabled, then the users should only sign-in via reverse proxy auth.
|
||||
// TODO: in the future, if we need to distinguish different sign-in methods, we need to save the sign-in method in session and check here
|
||||
if setting.Service.EnableReverseProxyAuth && setting.ReverseProxyLogoutRedirect != "" {
|
||||
return setting.ReverseProxyLogoutRedirect
|
||||
}
|
||||
return setting.AppSubURL + "/"
|
||||
}
|
||||
|
||||
// shouldRedirectToOIDCEndSession reports whether this session should end at the
|
||||
// OIDC provider. Prefer the session sign-in method so an OAuth2-linked account
|
||||
// that signed in with a password does not hit end_session_endpoint.
|
||||
func shouldRedirectToOIDCEndSession(ctx *context.Context) bool {
|
||||
return ctx.Session.Get(session.KeySignInMethod) == session.SignInMethodOAuth2
|
||||
}
|
||||
|
||||
func prepareSignUpPageData(ctx *context.Context) bool {
|
||||
ctx.Data["Title"] = ctx.Tr("sign_up")
|
||||
ctx.Data["SignUpLink"] = setting.AppSubURL + "/user/sign_up"
|
||||
|
||||
Reference in New Issue
Block a user