Skip to content

Commit

Permalink
Don't enforce persistence policy when impersonating
Browse files Browse the repository at this point in the history
  • Loading branch information
daftspunk committed Aug 20, 2021
1 parent f18f69f commit afd1868
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/Auth/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -679,9 +679,13 @@ public function logout()
/**
* setPersistCodeToSession stores the user persistence in the session and cookie.
*/
protected function setPersistCodeToSession($user, $remember = true): void
protected function setPersistCodeToSession($user, bool $remember = true, bool $impersonating = false): void
{
$toPersist = [$user->getKey(), $user->getPersistCode()];
$persistCode = $impersonating && $user->persist_code
? $user->persist_code
: $user->getPersistCode();

$toPersist = [$user->getKey(), $persistCode];

Session::put($this->sessionKey, $toPersist);

Expand All @@ -694,7 +698,7 @@ protected function setPersistCodeToSession($user, $remember = true): void
* getPersistCodeFromSession will return the user ID and persist token from the session.
* The resulting array will contain the user ID and persistence code [id, code] or null.
*/
protected function getPersistCodeFromSession($isChecking = true): ?array
protected function getPersistCodeFromSession(bool $isChecking = true): ?array
{
// Check session first, followed by cookie
if ($sessionArray = Session::get($this->sessionKey)) {
Expand Down Expand Up @@ -745,7 +749,7 @@ public function impersonate($user)
$user->fireEvent('model.auth.beforeImpersonate', [$oldUser]);

// Replace session with impersonated user
$this->setPersistCodeToSession($user, false);
$this->setPersistCodeToSession($user, false, true);

// If this is the first time impersonating, capture the original user
if (!$this->isImpersonator()) {
Expand Down Expand Up @@ -780,7 +784,7 @@ public function stopImpersonate()

// Restore previous user, if possible
if ($oldUser) {
$this->setPersistCodeToSession($oldUser, false);
$this->setPersistCodeToSession($oldUser, false, true);
}
else {
Session::forget($this->sessionKey);
Expand Down

0 comments on commit afd1868

Please sign in to comment.