diff --git a/src/Illuminate/Auth/Guard.php b/src/Illuminate/Auth/Guard.php index fd7aca35..c3b96d11 100755 --- a/src/Illuminate/Auth/Guard.php +++ b/src/Illuminate/Auth/Guard.php @@ -149,7 +149,6 @@ public function user() // pull the user data on that cookie which serves as a remember cookie on // the application. Once we have a user we can return it to the caller. $recaller = $this->getRecaller(); - if (is_null($user) && ! is_null($recaller)) { $user = $this->getUserByRecaller($recaller); @@ -167,7 +166,7 @@ public function id() { if ($this->loggedOut) return; - $id = $this->session->get($this->getName(), $this->getRecallerId()); + $id = $this->session->get($this->getName()); if (is_null($id) && $this->user()) { @@ -210,15 +209,14 @@ protected function getRecaller() /** * Get the user ID from the recaller cookie. * - * @return string + * @return int */ - protected function getRecallerId() - { - if ($this->validRecaller($recaller = $this->getRecaller())) - { - return head(explode('|', $recaller)); - } - } + protected function getRecallerId() + { + if ($this->validRecaller($recaller = $this->getRecaller())) { + return (int) head(explode('|', $recaller)); + } + } /** * Determine if the recaller cookie is in a valid format. diff --git a/tests/Auth/AuthGuardTest.php b/tests/Auth/AuthGuardTest.php index 04c63619..454e95fb 100755 --- a/tests/Auth/AuthGuardTest.php +++ b/tests/Auth/AuthGuardTest.php @@ -374,4 +374,27 @@ public function testUserUsesRememberCookieIfItExists() $this->assertEquals($user->reveal(), $guard->user()); $this->assertTrue($guard->viaRemember()); } + + public function testGetIdWhenRememberCookieExistsWillReturnIntegerIdFromCookieValue() + { + $request = Request::create('/', 'GET', [], [ + 'remember_82e5d2c56bdd0811318f0cf078b78bfc' => '123|recaller' + ]); + $user = $this->prophesize(UserInterface::class); + $user->getAuthIdentifier()->willReturn(123); + + $this->userProvider + ->retrieveByToken(123, 'recaller') + ->willReturn($user->reveal()); + + $guard = new Guard( + $this->userProvider->reveal(), + $this->session->reveal(), + $request + ); + + $this->assertNotNull($guard->id()); + $this->assertIsInt($guard->id()); + $this->assertSame(123, $guard->id()); + } }