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.

43 lines
786 B

7 years ago
  1. package auth
  2. import "strings"
  3. var methods []Authenticator
  4. // Register a method
  5. func Register(method Authenticator) {
  6. methods = append(methods, method)
  7. }
  8. // FindAuthenticator finds the first Method that answers with
  9. // the ID().
  10. func FindAuthenticator(id string) Authenticator {
  11. for _, method := range methods {
  12. if method.ID() == id {
  13. return method
  14. }
  15. }
  16. return nil
  17. }
  18. // ListAuthenticators gets a copy of the method list
  19. func ListAuthenticators() []Authenticator {
  20. dst := make([]Authenticator, len(methods))
  21. copy(dst, methods)
  22. return dst
  23. }
  24. func FindUser(fullid string) *User {
  25. split := strings.SplitN(fullid, ":", 2)
  26. autherID := split[0]
  27. userID := split[1]
  28. auther := FindAuthenticator(autherID)
  29. if auther == nil {
  30. return nil
  31. }
  32. return auther.Find(userID)
  33. }