@@ -8,7 +8,6 @@ package auth
8
8
import (
9
9
"fmt"
10
10
"net/http"
11
- "reflect"
12
11
"regexp"
13
12
"strings"
14
13
@@ -21,75 +20,22 @@ import (
21
20
"code.gitea.io/gitea/modules/web/middleware"
22
21
)
23
22
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
-
39
23
// The purpose of the following three function variables is to let the linter know that
40
24
// those functions are not dead code and are actually being used
41
25
var (
42
26
_ = handleSignIn
43
- )
44
-
45
- // Methods returns the instances of all registered methods
46
- func Methods () []Method {
47
- return authMethods
48
- }
49
27
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
+ )
54
32
55
33
// Init should be called exactly once when the application starts to allow plugins
56
34
// to allocate necessary resources
57
35
func 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
-
74
36
webauthn .Init ()
75
37
}
76
38
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
-
93
39
// isAttachmentDownload check if request is a file download (GET) with URL to an attachment
94
40
func isAttachmentDownload (req * http.Request ) bool {
95
41
return strings .HasPrefix (req .URL .Path , "/attachments/" ) && req .Method == "GET"
0 commit comments