Skip to content
This repository has been archived by the owner on Feb 17, 2024. It is now read-only.

Commit

Permalink
Fix bug with multiple calls to isAuthenticated
Browse files Browse the repository at this point in the history
  • Loading branch information
lambdacasserole committed Sep 25, 2016
1 parent 52147d5 commit 18cf112
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/Authenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ class Authenticator
*/
private $config;

/**
* Holds the cookie token during the current request.
*
* @var string
*/
private $cookieToken;

/**
* Dispenses a randomly generated authentication token.
*
Expand Down Expand Up @@ -71,9 +78,15 @@ private function validateToken($token)
*/
public function getCookieToken()
{
// If we have accessed the cookie token this request already.
if ($this->cookieToken !== null) {
return $this->cookieToken;
}

$name = $this->config->getCookieName();
$encrypted = isset($_COOKIE[$name]) ? $_COOKIE[$name] : ''; // Read encrypted cookie.
$plain = Encryption::decrypt($encrypted, $this->config->getSecretKey()); // Decrypt cookie.
$this->cookieToken = $plain; // Don't access cookie again.

return $plain;
}
Expand All @@ -85,6 +98,7 @@ public function getCookieToken()
*/
public function setCookieToken($token)
{
$this->cookieToken = $token; // Remember this for this request.
$encrypted = Encryption::encrypt($token, $this->config->getSecretKey()); // Encrypt token.

// Set cookie on client.
Expand Down

0 comments on commit 18cf112

Please sign in to comment.