Allow multiple authenticator classes

This commit is contained in:
Niklas 2021-07-06 09:50:16 +02:00
parent c11b7cdcda
commit fa589c25fb

View File

@ -59,9 +59,11 @@ class RestfulServer extends Controller
/** /**
* @config * @config
* @var string Class name for an authenticator to use on API access * @var array Class names for an authenticators to use on API access
*/ */
private static $authenticator = BasicRestfulAuthenticator::class; private static $authenticators = [
BasicRestfulAuthenticator::class
];
/** /**
* If no extension is given in the request, resolve to this extension * If no extension is given in the request, resolve to this extension
@ -854,8 +856,13 @@ class RestfulServer extends Controller
*/ */
protected function authenticate() protected function authenticate()
{ {
$authClass = $this->config()->authenticator; $authClasses = $this->config()->authenticators;
$member = $authClass::authenticate(); $member = null;
foreach ($authClasses as $authClass) {
if ($member = $authClass::authenticate()) {
break;
}
}
Security::setCurrentUser($member); Security::setCurrentUser($member);
return $member; return $member;
} }