@@ -8,7 +8,6 @@ package auth
88import (
99 "fmt"
1010 "net/http"
11- "reflect"
1211 "regexp"
1312 "strings"
1413
@@ -21,75 +20,22 @@ import (
2120 "code.gitea.io/gitea/modules/web/middleware"
2221)
2322
24- // authMethods contains the list of authentication plugins in the order they are expected to be
25- // executed.
26- //
27- // The OAuth2 plugin is expected to be executed first, as it must ignore the user id stored
28- // in the session (if there is a user id stored in session other plugins might return the user
29- // object for that id).
30- //
31- // The Session plugin is expected to be executed second, in order to skip authentication
32- // for users that have already signed in.
33- var authMethods = []Method {
34- & OAuth2 {},
35- & Basic {},
36- & Session {},
37- }
38-
3923// The purpose of the following three function variables is to let the linter know that
4024// those functions are not dead code and are actually being used
4125var (
4226 _ = handleSignIn
43- )
44-
45- // Methods returns the instances of all registered methods
46- func Methods () []Method {
47- return authMethods
48- }
4927
50- // Register adds the specified instance to the list of available methods
51- func Register ( method Method ) {
52- authMethods = append ( authMethods , method )
53- }
28+ // SharedSession the session auth should only be used by web, but now both web and API/v1
29+ // will use it. We can remove this after Web removed dependent API/v1
30+ SharedSession = & Session {}
31+ )
5432
5533// Init should be called exactly once when the application starts to allow plugins
5634// to allocate necessary resources
5735func Init () {
58- if setting .Service .EnableReverseProxyAuth {
59- Register (& ReverseProxy {})
60- }
61- specialInit ()
62- for _ , method := range Methods () {
63- initializable , ok := method .(Initializable )
64- if ! ok {
65- continue
66- }
67-
68- err := initializable .Init ()
69- if err != nil {
70- log .Error ("Could not initialize '%s' auth method, error: %s" , reflect .TypeOf (method ).String (), err )
71- }
72- }
73-
7436 webauthn .Init ()
7537}
7638
77- // Free should be called exactly once when the application is terminating to allow Auth plugins
78- // to release necessary resources
79- func Free () {
80- for _ , method := range Methods () {
81- freeable , ok := method .(Freeable )
82- if ! ok {
83- continue
84- }
85-
86- err := freeable .Free ()
87- if err != nil {
88- log .Error ("Could not free '%s' auth method, error: %s" , reflect .TypeOf (method ).String (), err )
89- }
90- }
91- }
92-
9339// isAttachmentDownload check if request is a file download (GET) with URL to an attachment
9440func isAttachmentDownload (req * http.Request ) bool {
9541 return strings .HasPrefix (req .URL .Path , "/attachments/" ) && req .Method == "GET"
0 commit comments