`Named` is implemented by every `Method` and future implementations should implement the method too.
Unified · Split
| @@ -36,6 +36,8 @@ var ( · 35 unmodified lines | ||
| 36 | 36 | algorithmPattern = regexp.MustCompile(`algorithm=(\w+)`) |
| 37 | 37 | versionPattern = regexp.MustCompile(`version=(\d+\.\d+)`) |
| 38 | 38 | authorizationPattern = regexp.MustCompile(`\AX-Ops-Authorization-(\d+)`) |
| 39 | + | |
| 40 | + _ auth.Method = &Auth{} | |
| 39 | 41 | ) |
| 40 | 42 | |
| 41 | 43 | // Documentation: |
| @@ -12,6 +12,8 @@ import ( · 11 unmodified lines | ||
| 12 | 12 | "code.gitea.io/gitea/services/packages" |
| 13 | 13 | ) |
| 14 | 14 | |
| 15 | +var _ auth.Method = &Auth{} | |
| 16 | + | |
| 15 | 17 | type Auth struct{} |
| 16 | 18 | |
| 17 | 19 | func (a *Auth) Name() string { |
| @@ -12,6 +12,8 @@ import ( · 11 unmodified lines | ||
| 12 | 12 | "code.gitea.io/gitea/services/packages" |
| 13 | 13 | ) |
| 14 | 14 | |
| 15 | +var _ auth.Method = &Auth{} | |
| 16 | + | |
| 15 | 17 | type Auth struct{} |
| 16 | 18 | |
| 17 | 19 | func (a *Auth) Name() string { |
| @@ -13,6 +13,8 @@ import ( · 12 unmodified lines | ||
| 13 | 13 | "code.gitea.io/gitea/services/auth" |
| 14 | 14 | ) |
| 15 | 15 | |
| 16 | +var _ auth.Method = &Auth{} | |
| 17 | + | |
| 16 | 18 | type Auth struct{} |
| 17 | 19 | |
| 18 | 20 | func (a *Auth) Name() string { |
| @@ -21,7 +21,6 @@ import ( · 20 unmodified lines | ||
| 21 | 21 | // Ensure the struct implements the interface. |
| 22 | 22 | var ( |
| 23 | 23 | _ Method = &Basic{} |
| 24 | − _ Named = &Basic{} | |
| 25 | 24 | ) |
| 26 | 25 | |
| 27 | 26 | // BasicMethodName is the constant name of the basic authentication method |
| @@ -5,7 +5,6 @@ package auth · 4 unmodified lines | ||
| 5 | 5 | |
| 6 | 6 | import ( |
| 7 | 7 | "net/http" |
| 8 | − "reflect" | |
| 9 | 8 | "strings" |
| 10 | 9 | |
| 11 | 10 | user_model "code.gitea.io/gitea/models/user" |
| @@ -37,21 +36,16 @@ func (b *Group) Add(method Method) { · 25 unmodified lines | ||
| 37 | 36 | func (b *Group) Name() string { |
| 38 | 37 | names := make([]string, 0, len(b.methods)) |
| 39 | 38 | for _, m := range b.methods { |
| 40 | − if n, ok := m.(Named); ok { | |
| 41 | − names = append(names, n.Name()) | |
| 42 | − } else { | |
| 43 | − names = append(names, reflect.TypeOf(m).Elem().Name()) | |
| 44 | − } | |
| 39 | + names = append(names, m.Name()) | |
| 45 | 40 | } |
| 46 | 41 | return strings.Join(names, ",") |
| 47 | 42 | } |
| 48 | 43 | |
| 49 | −// Verify extracts and validates | |
| 50 | 44 | func (b *Group) Verify(req *http.Request, w http.ResponseWriter, store DataStore, sess SessionStore) (*user_model.User, error) { |
| 51 | 45 | // Try to sign in with each of the enabled plugins |
| 52 | 46 | var retErr error |
| 53 | − for _, ssoMethod := range b.methods { | |
| 54 | − user, err := ssoMethod.Verify(req, w, store, sess) | |
| 47 | + for _, m := range b.methods { | |
| 48 | + user, err := m.Verify(req, w, store, sess) | |
| 55 | 49 | if err != nil { |
| 56 | 50 | if retErr == nil { |
| 57 | 51 | retErr = err |
| @@ -67,9 +61,7 @@ func (b *Group) Verify(req *http.Request, w http.ResponseWriter, store DataStore · 9 unmodified lines | ||
| 67 | 61 | // Return the user and ignore any error returned by previous methods. |
| 68 | 62 | if user != nil { |
| 69 | 63 | if store.GetData()["AuthedMethod"] == nil { |
| 70 | − if named, ok := ssoMethod.(Named); ok { | |
| 71 | − store.GetData()["AuthedMethod"] = named.Name() | |
| 72 | − } | |
| 64 | + store.GetData()["AuthedMethod"] = m.Name() | |
| 73 | 65 | } |
| 74 | 66 | return user, nil |
| 75 | 67 | } |
| @@ -23,7 +23,6 @@ import ( · 22 unmodified lines | ||
| 23 | 23 | // Ensure the struct implements the interface. |
| 24 | 24 | var ( |
| 25 | 25 | _ Method = &HTTPSign{} |
| 26 | − _ Named = &HTTPSign{} | |
| 27 | 26 | ) |
| 28 | 27 | |
| 29 | 28 | // HTTPSign implements the Auth interface and authenticates requests (API requests |
| @@ -27,10 +27,7 @@ type Method interface { · 26 unmodified lines | ||
| 27 | 27 | // Second argument returns err if verification fails, otherwise |
| 28 | 28 | // First return argument returns nil if no matched verification condition |
| 29 | 29 | Verify(http *http.Request, w http.ResponseWriter, store DataStore, sess SessionStore) (*user_model.User, error) |
| 30 | −} | |
| 31 | 30 | |
| 32 | −// Named represents a named thing | |
| 33 | −type Named interface { | |
| 34 | 31 | Name() string |
| 35 | 32 | } |
| 36 | 33 | |
| @@ -22,7 +22,6 @@ import ( · 21 unmodified lines | ||
| 22 | 22 | // Ensure the struct implements the interface. |
| 23 | 23 | var ( |
| 24 | 24 | _ Method = &OAuth2{} |
| 25 | − _ Named = &OAuth2{} | |
| 26 | 25 | ) |
| 27 | 26 | |
| 28 | 27 | // CheckOAuthAccessToken returns uid of user from oauth token |
| @@ -20,7 +20,6 @@ import ( · 19 unmodified lines | ||
| 20 | 20 | // Ensure the struct implements the interface. |
| 21 | 21 | var ( |
| 22 | 22 | _ Method = &ReverseProxy{} |
| 23 | − _ Named = &ReverseProxy{} | |
| 24 | 23 | ) |
| 25 | 24 | |
| 26 | 25 | // ReverseProxyMethodName is the constant name of the ReverseProxy authentication method |
| @@ -14,7 +14,6 @@ import ( · 13 unmodified lines | ||
| 14 | 14 | // Ensure the struct implements the interface. |
| 15 | 15 | var ( |
| 16 | 16 | _ Method = &Session{} |
| 17 | − _ Named = &Session{} | |
| 18 | 17 | ) |
| 19 | 18 | |
| 20 | 19 | // Session checks if there is a user uid stored in the session and returns the user |
| @@ -37,7 +37,6 @@ var ( · 36 unmodified lines | ||
| 37 | 37 | |
| 38 | 38 | // Ensure the struct implements the interface. |
| 39 | 39 | _ Method = &SSPI{} |
| 40 | − _ Named = &SSPI{} | |
| 41 | 40 | ) |
| 42 | 41 | |
| 43 | 42 | // SSPI implements the SingleSignOn interface and authenticates requests |