Skip to content

Commit

Permalink
Merge pull request barryvdh#564 from plapinski/issue/532
Browse files Browse the repository at this point in the history
fix for issue barryvdh#532 - MultiAuthCollector cause session token regeneration
  • Loading branch information
barryvdh authored Nov 21, 2016
2 parents b977458 + ffc7dd8 commit eb90bb8
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/DataCollector/MultiAuthCollector.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php

namespace Barryvdh\Debugbar\DataCollector;
use Illuminate\Contracts\Auth\Guard;
use Illuminate\Auth\SessionGuard;

/**
* Collector for Laravel's Auth provider
Expand Down Expand Up @@ -30,8 +32,10 @@ public function collect()
$names = '';

foreach($this->guards as $guardName) {
$user = $this->auth->guard($guardName)->user();
$user = $this->resolveUser($this->auth->guard($guardName));

$data['guards'][$guardName] = $this->getUserInformation($user);

if(!is_null($user)) {
$names .= $guardName . ": " . $data['guards'][$guardName]['name'] . ', ';
}
Expand All @@ -47,6 +51,23 @@ public function collect()

return $data;
}

private function resolveUser(Guard $guard)
{
// if we're logging in using remember token
// then we must resolve user „manually”
// to prevent csrf token regeneration

$usingSession = $guard instanceof SessionGuard;
$recaller = $usingSession ? $guard->getRequest()->cookies->get($guard->getRecallerName()) : null;

if($usingSession && !is_null($recaller)) {
list($id, $token) = explode('|', $recaller);
return $guard->getProvider()->retrieveByToken($id, $token);
} else {
return $guard->user();
}
}

/**
* @{inheritDoc}
Expand Down

0 comments on commit eb90bb8

Please sign in to comment.