Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade firebase/php-jwt to ^6.0 #1538

Merged
merged 1 commit into from
Mar 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"require": {
"php": "^7.3|^8.0",
"ext-json": "*",
"firebase/php-jwt": "^5.0",
"firebase/php-jwt": "^6.0",
"illuminate/auth": "^8.37|^9.0",
"illuminate/console": "^8.37|^9.0",
"illuminate/container": "^8.37|^9.0",
Expand Down
2 changes: 1 addition & 1 deletion src/ApiTokenCookieFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,6 @@ protected function createToken($userId, $csrfToken, Carbon $expiration)
'sub' => $userId,
'csrf' => $csrfToken,
'expiry' => $expiration->getTimestamp(),
], Passport::tokenEncryptionKey($this->encrypter));
], Passport::tokenEncryptionKey($this->encrypter), 'HS256');
}
}
4 changes: 2 additions & 2 deletions src/Guards/TokenGuard.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Exception;
use Firebase\JWT\JWT;
use Firebase\JWT\Key;
use Illuminate\Container\Container;
use Illuminate\Contracts\Debug\ExceptionHandler;
use Illuminate\Contracts\Encryption\Encrypter;
Expand Down Expand Up @@ -269,8 +270,7 @@ protected function decodeJwtTokenCookie($request)
{
return (array) JWT::decode(
CookieValuePrefix::remove($this->encrypter->decrypt($request->cookie(Passport::cookie()), Passport::$unserializesCookies)),
Passport::tokenEncryptionKey($this->encrypter),
['HS256']
new Key(Passport::tokenEncryptionKey($this->encrypter), 'HS256')
);
}

Expand Down
18 changes: 9 additions & 9 deletions tests/Unit/TokenGuardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public function test_users_may_be_retrieved_from_cookies_with_csrf_token_header(
'aud' => 1,
'csrf' => 'token',
'expiry' => Carbon::now()->addMinutes(10)->getTimestamp(),
], str_repeat('a', 16)), false)
], str_repeat('a', 16), 'HS256'), false)
);

$userProvider->shouldReceive('retrieveById')->with(1)->andReturn($expectedUser = new TokenGuardTestUser);
Expand Down Expand Up @@ -167,7 +167,7 @@ public function test_users_may_be_retrieved_from_cookies_with_xsrf_token_header(
'aud' => 1,
'csrf' => 'token',
'expiry' => Carbon::now()->addMinutes(10)->getTimestamp(),
], str_repeat('a', 16)), false)
], str_repeat('a', 16), 'HS256'), false)
);

$userProvider->shouldReceive('retrieveById')->with(1)->andReturn($expectedUser = new TokenGuardTestUser);
Expand Down Expand Up @@ -196,7 +196,7 @@ public function test_cookie_xsrf_is_verified_against_csrf_token_header()
'aud' => 1,
'csrf' => 'token',
'expiry' => Carbon::now()->addMinutes(10)->getTimestamp(),
], str_repeat('a', 16)))
], str_repeat('a', 16), 'HS256'))
);

$userProvider->shouldReceive('retrieveById')->never();
Expand All @@ -222,7 +222,7 @@ public function test_cookie_xsrf_is_verified_against_xsrf_token_header()
'aud' => 1,
'csrf' => 'token',
'expiry' => Carbon::now()->addMinutes(10)->getTimestamp(),
], str_repeat('a', 16)))
], str_repeat('a', 16), 'HS256'))
);

$userProvider->shouldReceive('retrieveById')->never();
Expand Down Expand Up @@ -256,7 +256,7 @@ public function test_users_may_be_retrieved_from_cookies_with_xsrf_token_header_
'aud' => 1,
'csrf' => 'token',
'expiry' => Carbon::now()->addMinutes(10)->getTimestamp(),
], Passport::tokenEncryptionKey($encrypter)), false)
], Passport::tokenEncryptionKey($encrypter), 'HS256'), false)
);

$userProvider->shouldReceive('retrieveById')->with(1)->andReturn($expectedUser = new TokenGuardTestUser);
Expand Down Expand Up @@ -288,7 +288,7 @@ public function test_xsrf_token_cookie_without_a_token_header_is_not_accepted()
'aud' => 1,
'csrf' => 'token',
'expiry' => Carbon::now()->addMinutes(10)->getTimestamp(),
], str_repeat('a', 16)))
], str_repeat('a', 16), 'HS256'))
);

$userProvider->shouldReceive('retrieveById')->never();
Expand All @@ -314,7 +314,7 @@ public function test_expired_cookies_may_not_be_used()
'aud' => 1,
'csrf' => 'token',
'expiry' => Carbon::now()->subMinutes(10)->getTimestamp(),
], str_repeat('a', 16)))
], str_repeat('a', 16), 'HS256'))
);

$userProvider->shouldReceive('retrieveById')->never();
Expand Down Expand Up @@ -344,7 +344,7 @@ public function test_csrf_check_can_be_disabled()
'sub' => 1,
'aud' => 1,
'expiry' => Carbon::now()->addMinutes(10)->getTimestamp(),
], str_repeat('a', 16)), false)
], str_repeat('a', 16), 'HS256'), false)
);

$userProvider->shouldReceive('retrieveById')->with(1)->andReturn($expectedUser = new TokenGuardTestUser);
Expand Down Expand Up @@ -443,7 +443,7 @@ public function test_clients_may_be_retrieved_from_cookies()
'aud' => 1,
'csrf' => 'token',
'expiry' => Carbon::now()->addMinutes(10)->getTimestamp(),
], str_repeat('a', 16)), false)
], str_repeat('a', 16), 'HS256'), false)
);

$clients->shouldReceive('findActive')->with(1)->andReturn($expectedClient = new TokenGuardTestClient);
Expand Down