Core functionality for new aiterp.net servers
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.

46 lines
853 B

package auth
import (
"errors"
"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, error) {
split := strings.SplitN(fullid, ":", 2)
autherID := split[0]
userID := split[1]
auther := FindAuthenticator(autherID)
if auther == nil {
return nil, errors.New("auth: auther not found")
}
return auther.Find(userID), nil
}