|
|
@ -5,7 +5,6 @@ package auth |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
import ( |
|
|
|
"net/http" |
|
|
|
"net/http" |
|
|
|
"reflect" |
|
|
|
|
|
|
|
"strings" |
|
|
|
"strings" |
|
|
|
|
|
|
|
|
|
|
|
user_model "code.gitea.io/gitea/models/user" |
|
|
|
user_model "code.gitea.io/gitea/models/user" |
|
|
@ -37,21 +36,16 @@ func (b *Group) Add(method Method) { |
|
|
|
func (b *Group) Name() string { |
|
|
|
func (b *Group) Name() string { |
|
|
|
names := make([]string, 0, len(b.methods)) |
|
|
|
names := make([]string, 0, len(b.methods)) |
|
|
|
for _, m := range b.methods { |
|
|
|
for _, m := range b.methods { |
|
|
|
if n, ok := m.(Named); ok { |
|
|
|
names = append(names, m.Name()) |
|
|
|
names = append(names, n.Name()) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
names = append(names, reflect.TypeOf(m).Elem().Name()) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
return strings.Join(names, ",") |
|
|
|
return strings.Join(names, ",") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Verify extracts and validates
|
|
|
|
|
|
|
|
func (b *Group) Verify(req *http.Request, w http.ResponseWriter, store DataStore, sess SessionStore) (*user_model.User, error) { |
|
|
|
func (b *Group) Verify(req *http.Request, w http.ResponseWriter, store DataStore, sess SessionStore) (*user_model.User, error) { |
|
|
|
// Try to sign in with each of the enabled plugins
|
|
|
|
// Try to sign in with each of the enabled plugins
|
|
|
|
var retErr error |
|
|
|
var retErr error |
|
|
|
for _, ssoMethod := range b.methods { |
|
|
|
for _, m := range b.methods { |
|
|
|
user, err := ssoMethod.Verify(req, w, store, sess) |
|
|
|
user, err := m.Verify(req, w, store, sess) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
if retErr == nil { |
|
|
|
if retErr == nil { |
|
|
|
retErr = err |
|
|
|
retErr = err |
|
|
@ -67,9 +61,7 @@ func (b *Group) Verify(req *http.Request, w http.ResponseWriter, store DataStore |
|
|
|
// Return the user and ignore any error returned by previous methods.
|
|
|
|
// Return the user and ignore any error returned by previous methods.
|
|
|
|
if user != nil { |
|
|
|
if user != nil { |
|
|
|
if store.GetData()["AuthedMethod"] == nil { |
|
|
|
if store.GetData()["AuthedMethod"] == nil { |
|
|
|
if named, ok := ssoMethod.(Named); ok { |
|
|
|
store.GetData()["AuthedMethod"] = m.Name() |
|
|
|
store.GetData()["AuthedMethod"] = named.Name() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
return user, nil |
|
|
|
return user, nil |
|
|
|
} |
|
|
|
} |
|
|
|