You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
786 B
43 lines
786 B
package auth
|
|
|
|
import "strings"
|
|
|
|
var methods []Authenticator
|
|
|
|
// Register a method
|
|
func Register(method Authenticator) {
|
|
methods = append(methods, method)
|
|
}
|
|
|
|
// FindAuthenticator finds the first Method that answers with
|
|
// the ID().
|
|
func FindAuthenticator(id string) Authenticator {
|
|
for _, method := range methods {
|
|
if method.ID() == id {
|
|
return method
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// ListAuthenticators gets a copy of the method list
|
|
func ListAuthenticators() []Authenticator {
|
|
dst := make([]Authenticator, len(methods))
|
|
copy(dst, methods)
|
|
|
|
return dst
|
|
}
|
|
|
|
func FindUser(fullid string) *User {
|
|
split := strings.SplitN(fullid, ":", 2)
|
|
autherID := split[0]
|
|
userID := split[1]
|
|
|
|
auther := FindAuthenticator(autherID)
|
|
if auther == nil {
|
|
return nil
|
|
}
|
|
|
|
return auther.Find(userID)
|
|
}
|