Skip to content

Commit ffc7dd8

Browse files
author
plapinski
committed
fix for issue barryvdh#532 - MultiAuthCollector cause session token regeneration
1 parent b977458 commit ffc7dd8

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/DataCollector/MultiAuthCollector.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php
22

33
namespace Barryvdh\Debugbar\DataCollector;
4+
use Illuminate\Contracts\Auth\Guard;
5+
use Illuminate\Auth\SessionGuard;
46

57
/**
68
* Collector for Laravel's Auth provider
@@ -30,8 +32,10 @@ public function collect()
3032
$names = '';
3133

3234
foreach($this->guards as $guardName) {
33-
$user = $this->auth->guard($guardName)->user();
35+
$user = $this->resolveUser($this->auth->guard($guardName));
36+
3437
$data['guards'][$guardName] = $this->getUserInformation($user);
38+
3539
if(!is_null($user)) {
3640
$names .= $guardName . ": " . $data['guards'][$guardName]['name'] . ', ';
3741
}
@@ -47,6 +51,23 @@ public function collect()
4751

4852
return $data;
4953
}
54+
55+
private function resolveUser(Guard $guard)
56+
{
57+
// if we're logging in using remember token
58+
// then we must resolve user „manually”
59+
// to prevent csrf token regeneration
60+
61+
$usingSession = $guard instanceof SessionGuard;
62+
$recaller = $usingSession ? $guard->getRequest()->cookies->get($guard->getRecallerName()) : null;
63+
64+
if($usingSession && !is_null($recaller)) {
65+
list($id, $token) = explode('|', $recaller);
66+
return $guard->getProvider()->retrieveByToken($id, $token);
67+
} else {
68+
return $guard->user();
69+
}
70+
}
5071

5172
/**
5273
* @{inheritDoc}

0 commit comments

Comments
 (0)