This commit is contained in:
Bastian Allgeier
2020-07-07 12:40:13 +02:00
parent 5f025ac2c2
commit f79d2e960c
176 changed files with 10532 additions and 5343 deletions

View File

@@ -85,6 +85,16 @@ class Auth
return $this->validatePassword($auth->username(), $auth->password());
}
/**
* Returns the currently impersonated user
*
* @return \Kirby\Cms\User|null
*/
public function currentUserFromImpersonation()
{
return $this->impersonate;
}
/**
* Returns the logged in user by checking
* the current session and finding a valid
@@ -124,10 +134,10 @@ class Auth
/**
* Become any existing user
*
* @param string|null $who
* @param string|null $who User ID or email address
* @return \Kirby\Cms\User|null
*/
public function impersonate(string $who = null)
public function impersonate(?string $who = null)
{
switch ($who) {
case null:
@@ -416,16 +426,19 @@ class Auth
/**
* Returns the current authentication type
*
* @param bool $allowImpersonation If set to false, 'impersonate' won't
* be returned as authentication type
* even if an impersonation is active
* @return string
*/
public function type(): string
public function type(bool $allowImpersonation = true): string
{
$basicAuth = $this->kirby->option('api.basicAuth', false);
$auth = $this->kirby->request()->auth();
if ($basicAuth === true && $auth && $auth->type() === 'basic') {
return 'basic';
} elseif ($this->impersonate !== null) {
} elseif ($allowImpersonation === true && $this->impersonate !== null) {
return 'impersonate';
} else {
return 'session';
@@ -436,13 +449,15 @@ class Auth
* Validates the currently logged in user
*
* @param \Kirby\Session\Session|array|null $session
* @param bool $allowImpersonation If set to false, only the actually
* logged in user will be returned
* @return \Kirby\Cms\User
*
* @throws \Throwable If an authentication error occured
*/
public function user($session = null)
public function user($session = null, bool $allowImpersonation = true)
{
if ($this->impersonate !== null) {
if ($allowImpersonation === true && $this->impersonate !== null) {
return $this->impersonate;
}