Skip to content
This repository was archived by the owner on Jun 18, 2023. It is now read-only.

Commit b2a8eff

Browse files
authored
Merge pull request #9 from deweppro/auth-cookie
fix auth cookie
2 parents 3547f6a + 7c7eea8 commit b2a8eff

File tree

1 file changed

+13
-18
lines changed

1 file changed

+13
-18
lines changed

src/Dewep/Middleware/Auth/Cookies.php

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@
77
use Dewep\Middleware\BaseClass;
88

99
/**
10-
* Class CookieUserAuth
11-
*
12-
* @package Dewep\Middleware\CookieUserAuth
13-
*
1410
* @example :
1511
* Dewep\Middleware\CookieUserAuth:
1612
* alg: gost-crypto
@@ -22,22 +18,16 @@ class Cookies extends BaseClass
2218
{
2319
const ALGO_DEFAULT = 'gost-crypto';
2420

25-
/**
26-
* @var array
27-
*/
21+
/** @var array */
2822
private static $payload = [];
2923

30-
/**
31-
* @var array
32-
*/
24+
/** @var array */
3325
private static $header = [
3426
'alg' => self::ALGO_DEFAULT,
3527
'exp' => 0,
3628
];
3729

38-
/**
39-
* @var bool
40-
*/
30+
/** @var bool */
4131
private static $changed = false;
4232

4333
/**
@@ -119,11 +109,14 @@ public function before(Request $request, Response $response, array $params)
119109
return false;
120110
}
121111

122-
@list($header, $payload, $sign) = $tokenData;
112+
[$header, $payload, $sign] = $tokenData;
123113

124114
$headerData = $this->base64JsonDecode($header);
125115
if (
126-
($headerData['alg'] ?? '') !== $this->getParam('alg', self::ALGO_DEFAULT) ||
116+
($headerData['alg'] ?? '') !== $this->getParam(
117+
'alg',
118+
self::ALGO_DEFAULT
119+
) ||
127120
(int)($headerData['exp'] ?? 0) < time()
128121
) {
129122
self::$payload = [];
@@ -154,7 +147,7 @@ public function before(Request $request, Response $response, array $params)
154147
*
155148
* @return array
156149
*/
157-
private function base64JsonDecode(string $str): array
150+
protected function base64JsonDecode(string $str): array
158151
{
159152
$data = json_decode((string)base64_decode($str), true);
160153
if (!is_array($data)) {
@@ -181,7 +174,9 @@ public function after(Request $request, Response $response, array $params)
181174
$response->getCookie()->set(
182175
$this->getParam('name', 'x-user-token'),
183176
$this->buildToken(),
184-
self::$header['exp']
177+
self::$header['exp'],
178+
'/',
179+
$this->getParam('domain')
185180
);
186181

187182
return true;
@@ -226,7 +221,7 @@ public function buildToken(): string
226221
*
227222
* @return string
228223
*/
229-
private function base64JsonEncode(array $data): string
224+
protected function base64JsonEncode(array $data): string
230225
{
231226
$str = base64_encode((string)json_encode($data));
232227
if (!is_string($str)) {

0 commit comments

Comments
 (0)