-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Let web and API routes have different auth methods group #19168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
346520a
5fc9986
3cb1d69
5de17ab
9900b1d
801b988
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Copyright 2022 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
//go:build !windows | ||
// +build !windows | ||
|
||
package v1 | ||
|
||
import auth_service "code.gitea.io/gitea/services/auth" | ||
|
||
func specialAdd(group *auth_service.Group) {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright 2022 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package v1 | ||
|
||
import ( | ||
"code.gitea.io/gitea/models/auth" | ||
auth_service "code.gitea.io/gitea/services/auth" | ||
) | ||
|
||
// specialAdd registers the SSPI auth method as the last method in the list. | ||
// The SSPI plugin is expected to be executed last, as it returns 401 status code if negotiation | ||
// fails (or if negotiation should continue), which would prevent other authentication methods | ||
// to execute at all. | ||
func specialAdd(group *auth_service.Group) { | ||
if auth.IsSSPIEnabled() { | ||
group.Add(&auth_service.SSPI{}) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Copyright 2022 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
//go:build !windows | ||
// +build !windows | ||
|
||
package web | ||
|
||
import auth_service "code.gitea.io/gitea/services/auth" | ||
|
||
func specialAdd(group *auth_service.Group) {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright 2022 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package web | ||
|
||
import ( | ||
"code.gitea.io/gitea/models/auth" | ||
auth_service "code.gitea.io/gitea/services/auth" | ||
) | ||
|
||
// specialAdd registers the SSPI auth method as the last method in the list. | ||
// The SSPI plugin is expected to be executed last, as it returns 401 status code if negotiation | ||
// fails (or if negotiation should continue), which would prevent other authentication methods | ||
// to execute at all. | ||
func specialAdd(group *auth_service.Group) { | ||
if auth.IsSSPIEnabled() { | ||
group.Add(&auth_service.SSPI{}) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,6 @@ package auth | |
import ( | ||
"fmt" | ||
"net/http" | ||
"reflect" | ||
"regexp" | ||
"strings" | ||
|
||
|
@@ -21,75 +20,22 @@ import ( | |
"code.gitea.io/gitea/modules/web/middleware" | ||
) | ||
|
||
// authMethods contains the list of authentication plugins in the order they are expected to be | ||
// executed. | ||
// | ||
// The OAuth2 plugin is expected to be executed first, as it must ignore the user id stored | ||
// in the session (if there is a user id stored in session other plugins might return the user | ||
// object for that id). | ||
// | ||
// The Session plugin is expected to be executed second, in order to skip authentication | ||
// for users that have already signed in. | ||
var authMethods = []Method{ | ||
&OAuth2{}, | ||
&Basic{}, | ||
&Session{}, | ||
} | ||
|
||
// The purpose of the following three function variables is to let the linter know that | ||
// those functions are not dead code and are actually being used | ||
var ( | ||
_ = handleSignIn | ||
) | ||
|
||
// Methods returns the instances of all registered methods | ||
func Methods() []Method { | ||
return authMethods | ||
} | ||
|
||
// Register adds the specified instance to the list of available methods | ||
func Register(method Method) { | ||
authMethods = append(authMethods, method) | ||
} | ||
// SharedSession the session auth should only be used by web, but now both web and API/v1 | ||
// will use it. We can remove this after Web removed dependent API/v1 | ||
SharedSession = &Session{} | ||
) | ||
|
||
// Init should be called exactly once when the application starts to allow plugins | ||
// to allocate necessary resources | ||
func Init() { | ||
if setting.Service.EnableReverseProxyAuth { | ||
Register(&ReverseProxy{}) | ||
} | ||
specialInit() | ||
for _, method := range Methods() { | ||
initializable, ok := method.(Initializable) | ||
if !ok { | ||
continue | ||
} | ||
|
||
err := initializable.Init() | ||
if err != nil { | ||
log.Error("Could not initialize '%s' auth method, error: %s", reflect.TypeOf(method).String(), err) | ||
} | ||
} | ||
|
||
webauthn.Init() | ||
} | ||
|
||
// Free should be called exactly once when the application is terminating to allow Auth plugins | ||
// to release necessary resources | ||
func Free() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was that simply unused, or why can't I find a replacement for it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Couldn't find any reference for this function. It's wired. |
||
for _, method := range Methods() { | ||
freeable, ok := method.(Freeable) | ||
if !ok { | ||
continue | ||
} | ||
|
||
err := freeable.Free() | ||
if err != nil { | ||
log.Error("Could not free '%s' auth method, error: %s", reflect.TypeOf(method).String(), err) | ||
} | ||
} | ||
} | ||
|
||
// isAttachmentDownload check if request is a file download (GET) with URL to an attachment | ||
func isAttachmentDownload(req *http.Request) bool { | ||
return strings.HasPrefix(req.URL.Path, "/attachments/") && req.Method == "GET" | ||
|
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.