Skip to content

Commit 95e8ea9

Browse files
authored
Allow setting redirect_to cookie on OAuth login (go-gitea#22594)
The regular login flow can use a `redirect_to` cookie to ensure the user ends their authentication flow on the same page as where they started it. This commit adds the same functionality to the OAuth login URLs, so that you can use URLs like these to directly use a specific OAuth provider: `/user/oauth2/{provider}?redirect_to={post-login path}` Only the `auth.SignInOAuth()` function needed a change for this, as the rest of the login flow is aware of this cookie and uses it properly already.
1 parent 9cc15d1 commit 95e8ea9

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

routers/web/auth/oauth.go

+5
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,11 @@ func SignInOAuth(ctx *context.Context) {
847847
return
848848
}
849849

850+
redirectTo := ctx.FormString("redirect_to")
851+
if len(redirectTo) > 0 {
852+
middleware.SetRedirectToCookie(ctx.Resp, redirectTo)
853+
}
854+
850855
// try to do a direct callback flow, so we don't authenticate the user again but use the valid accesstoken to get the user
851856
user, gothUser, err := oAuth2UserLoginCallback(authSource, ctx.Req, ctx.Resp)
852857
if err == nil && user != nil {

0 commit comments

Comments
 (0)