Skip to content

Commit e871146

Browse files
Merge pull request #197 from cakephp/fix-cookie-auth
Add support for expanded cookies
2 parents 3294fb0 + 3eea03d commit e871146

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

src/Authenticator/CookieAuthenticator.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,11 @@ public function authenticate(ServerRequestInterface $request, ResponseInterface
9191
]);
9292
}
9393

94-
$token = json_decode($cookies[$cookieName], true);
94+
if (is_array($cookies[$cookieName])) {
95+
$token = $cookies[$cookieName];
96+
} else {
97+
$token = json_decode($cookies[$cookieName], true);
98+
}
9599

96100
if ($token === null || count($token) !== 2) {
97101
return new Result(null, Result::FAILURE_CREDENTIALS_INVALID, [

tests/TestCase/Authenticator/CookieAuthenticatorTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,34 @@ public function testAuthenticateSuccess()
103103
$this->assertEquals(Result::SUCCESS, $result->getStatus());
104104
}
105105

106+
/**
107+
* testAuthenticateSuccess
108+
*
109+
* @return void
110+
*/
111+
public function testAuthenticateExpandedCookie()
112+
{
113+
$identifiers = new IdentifierCollection([
114+
'Authentication.Password'
115+
]);
116+
117+
$request = ServerRequestFactory::fromGlobals(
118+
['REQUEST_URI' => '/testpath'],
119+
null,
120+
null,
121+
[
122+
'CookieAuth' => ["mariano", "$2y$10$1bE1SgasKoz9WmEvUfuZLeYa6pQgxUIJ5LAoS/KGmC1hNuWkUG7ES"]
123+
]
124+
);
125+
$response = new Response();
126+
127+
$authenticator = new CookieAuthenticator($identifiers);
128+
$result = $authenticator->authenticate($request, $response);
129+
130+
$this->assertInstanceOf(Result::class, $result);
131+
$this->assertEquals(Result::SUCCESS, $result->getStatus());
132+
}
133+
106134
/**
107135
* testAuthenticateUnknownUser
108136
*

0 commit comments

Comments
 (0)