Skip to content

Commit

Permalink
Support for firebase/php-jwt Version 6 (#32)
Browse files Browse the repository at this point in the history
* wip

* wip

* wip
  • Loading branch information
bashgeek committed Apr 29, 2022
1 parent 61e5f98 commit 415e297
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 22 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
composer.phar
composer.lock
.DS_Store
.phpunit.result.cache
7 changes: 3 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,16 @@
"sign-in-with-apple"
],
"require": {
"league/oauth2-client": "^2.0",
"ext-json": "*",
"firebase/php-jwt": "^5.2",
"league/oauth2-client": "^2.0",
"firebase/php-jwt": "^6.0",
"lcobucci/jwt": "^3.4 || ^4.0"
},
"require-dev": {
"phpunit/phpunit": "^5.7 || ^6.0 || ^9.3",
"mockery/mockery": "^1.3",
"php-parallel-lint/php-parallel-lint": "^1.3",
"squizlabs/php_codesniffer": "^2.3 || ^3.0",
"ext-json": "*"
"squizlabs/php_codesniffer": "^2.3 || ^3.0"
},
"autoload": {
"psr-4": {
Expand Down
21 changes: 9 additions & 12 deletions src/Provider/Apple.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Firebase\JWT\JWK;
use InvalidArgumentException;
use Lcobucci\JWT\Configuration;
use Lcobucci\JWT\Signer\Key\LocalFileReference;
use Lcobucci\JWT\Signer\Key\InMemory;
use Lcobucci\JWT\Signer;
use Lcobucci\JWT\Signer\Key;
use League\OAuth2\Client\Grant\AbstractGrant;
Expand Down Expand Up @@ -252,24 +252,21 @@ public function getAccessToken($grant, array $options = [])
*/
public function getConfiguration()
{
if (method_exists(Signer\Ecdsa\Sha256::class, 'create')) {
return Configuration::forSymmetricSigner(
Signer\Ecdsa\Sha256::create(),
$this->getLocalKey()
);
} else {
return Configuration::forSymmetricSigner(
new Signer\Ecdsa\Sha256(),
$this->getLocalKey()
);
if (!method_exists(Signer\Ecdsa\Sha256::class, 'create')) {
throw new Exception('Cannot create Ecdsa\Sha256 configuration');
}

return Configuration::forSymmetricSigner(
Signer\Ecdsa\Sha256::create(),
$this->getLocalKey()
);
}

/**
* @return Key
*/
public function getLocalKey()
{
return LocalFileReference::file($this->keyFilePath);
return InMemory::file($this->keyFilePath);
}
}
7 changes: 3 additions & 4 deletions src/Token/AppleAccessToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

namespace League\OAuth2\Client\Token;

use Firebase\JWT\JWK;
use Firebase\JWT\JWT;
use GuzzleHttp\ClientInterface;
use Firebase\JWT\Key;
use InvalidArgumentException;

class AppleAccessToken extends AccessToken
Expand All @@ -27,7 +26,7 @@ class AppleAccessToken extends AccessToken
/**
* Constructs an access token.
*
* @param string[] $keys Valid Apple JWT keys
* @param Key[] $keys Valid Apple JWT keys
* @param array $options An array of options returned by the service provider
* in the access token request. The `access_token` option is required.
* @throws InvalidArgumentException if `access_token` is not provided in `$options`.
Expand All @@ -45,7 +44,7 @@ public function __construct(array $keys, array $options = [])
$last = end($keys);
foreach ($keys as $key) {
try {
$decoded = JWT::decode($options['id_token'], $key, ['RS256']);
$decoded = JWT::decode($options['id_token'], $key);
break;
} catch (\Exception $exception) {
if ($last === $key) {
Expand Down
7 changes: 5 additions & 2 deletions test/src/Token/AppleAccessTokenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace League\OAuth2\Client\Test\Token;

use Firebase\JWT\Key;
use League\OAuth2\Client\Token\AppleAccessToken;
use PHPUnit\Framework\TestCase;
use Mockery as m;
Expand All @@ -16,7 +17,7 @@ public function testCreatingAccessToken()
{
$externalJWTMock = m::mock('overload:Firebase\JWT\JWT');
$externalJWTMock->shouldReceive('decode')
->with('something', 'examplekey', ['RS256'])
->with('something', 'examplekey')
->once()
->andReturn([
'sub' => '123.abc.123',
Expand All @@ -37,6 +38,8 @@ public function testCreatingAccessToken()
$this->assertEquals('access_token', $accessToken->getToken());
$this->assertEquals('[email protected]', $accessToken->getEmail());
$this->assertTrue($accessToken->isPrivateEmail());

$this->assertTrue(true);
}

public function testCreateFailsBecauseNoIdTokenIsSet()
Expand Down Expand Up @@ -73,7 +76,7 @@ public function testCreatingAccessTokenFailsBecauseNoDecodingIsPossible()

$externalJWTMock = m::mock('overload:Firebase\JWT\JWT');
$externalJWTMock->shouldReceive('decode')
->with('something', 'examplekey', ['RS256'])
->with('something', 'examplekey')
->once()
->andReturnNull();

Expand Down

0 comments on commit 415e297

Please sign in to comment.