This commit is contained in:
2025-11-20 16:34:30 +01:00
parent 15d1a30e88
commit 4e4351e833
631 changed files with 130125 additions and 36318 deletions

View File

@@ -1,12 +1,12 @@
{
"name": "patrickbussmann\/oauth2-apple",
"name": "patrickbussmann/oauth2-apple",
"description": "Sign in with Apple OAuth 2.0 Client Provider for The PHP League OAuth2-Client",
"license": "MIT",
"authors": [
{
"name": "Patrick Bu\u00dfmann",
"name": "Patrick Bußmann",
"email": "patrick.bussmann@bussmann-it.de",
"homepage": "https:\/\/github.com\/patrickbussmann"
"homepage": "https://github.com/patrickbussmann"
}
],
"keywords": [
@@ -20,25 +20,25 @@
],
"require": {
"ext-json": "*",
"league\/oauth2-client": "^2.0",
"firebase\/php-jwt": "^5.2 || ^6.0",
"lcobucci\/jwt": "^3.4 || ^4.0 || ^5.0"
"league/oauth2-client": "^2.0",
"firebase/php-jwt": "^5.2 || ^6.0",
"lcobucci/jwt": "^3.4 || ^4.0 || ^5.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",
"composer\/semver": "^3.0"
"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",
"composer/semver": "^3.0"
},
"autoload": {
"psr-4": {
"Pshowsso\\Scope68f5e85e9608b\\League\\OAuth2\\Client\\": "src\/"
"League\\OAuth2\\Client\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Pshowsso\\Scope68f5e85e9608b\\League\\OAuth2\\Client\\Test\\": "test\/src\/"
"League\\OAuth2\\Client\\Test\\": "test/src/"
}
},
"extra": {
@@ -46,4 +46,4 @@
"dev-master": "0.4.x-dev"
}
}
}
}

View File

@@ -1,23 +1,27 @@
<?php
namespace Pshowsso\Scope68f5e85e9608b\League\OAuth2\Client\Test;
namespace League\OAuth2\Client\Test;
use Lcobucci\JWT\Signature;
use Lcobucci\JWT\Signer;
use Pshowsso\Scope68f5e85e9608b\Lcobucci\JWT\Signature;
use Pshowsso\Scope68f5e85e9608b\Lcobucci\JWT\Signer;
final class KeyDumpSigner implements Signer
{
public function getAlgorithmId()
{
return 'keydump';
}
public function modifyHeader(array &$headers)
{
$headers['alg'] = $this->getAlgorithmId();
}
public function verify($expected, $payload, $key)
{
return $expected === $key->contents();
}
public function sign($payload, $key)
{
return new Signature($key->contents());

View File

@@ -1,19 +1,22 @@
<?php
namespace Pshowsso\Scope68f5e85e9608b\League\OAuth2\Client\Test;
namespace League\OAuth2\Client\Test;
use Lcobucci\JWT\Signer;
use Lcobucci\JWT\Signer\Key;
use Pshowsso\Scope68f5e85e9608b\Lcobucci\JWT\Signer;
use Pshowsso\Scope68f5e85e9608b\Lcobucci\JWT\Signer\Key;
final class KeyDumpSigner implements Signer
{
public function algorithmId(): string
{
return 'keydump';
}
public function sign(string $payload, Key $key): string
{
return $key->contents();
}
public function verify(string $expected, string $payload, Key $key): bool
{
return $expected === $key->contents();

View File

@@ -1,9 +1,10 @@
<?php
namespace Pshowsso\Scope68f5e85e9608b\League\OAuth2\Client\Test;
namespace League\OAuth2\Client\Test;
use Composer\InstalledVersions;
use Composer\Semver\VersionParser;
if (!InstalledVersions::satisfies(new VersionParser(), 'lcobucci/jwt', '^1 || ^2 || ^3')) {
require_once __DIR__ . '/../ext/KeyDumpSigner8.php';
} else {

View File

@@ -1,56 +1,85 @@
<?php
namespace Pshowsso\Scope68f5e85e9608b\League\OAuth2\Client\Test\Provider;
namespace League\OAuth2\Client\Test\Provider;
use Pshowsso\Scope68f5e85e9608b\GuzzleHttp\ClientInterface;
use Pshowsso\Scope68f5e85e9608b\GuzzleHttp\Psr7\Response;
use Pshowsso\Scope68f5e85e9608b\Lcobucci\JWT\Configuration;
use Pshowsso\Scope68f5e85e9608b\Lcobucci\JWT\Signer\Key;
use Pshowsso\Scope68f5e85e9608b\Lcobucci\JWT\Signer\Hmac\Sha256;
use Pshowsso\Scope68f5e85e9608b\League\OAuth2\Client\Provider\Apple;
use Pshowsso\Scope68f5e85e9608b\League\OAuth2\Client\Provider\AppleResourceOwner;
use Pshowsso\Scope68f5e85e9608b\League\OAuth2\Client\Test\KeyDumpSigner;
use Pshowsso\Scope68f5e85e9608b\League\OAuth2\Client\Token\AccessToken;
use Pshowsso\Scope68f5e85e9608b\League\OAuth2\Client\Token\AppleAccessToken;
use Pshowsso\Scope68f5e85e9608b\League\OAuth2\Client\Tool\QueryBuilderTrait;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Psr7\Response;
use Lcobucci\JWT\Configuration;
use Lcobucci\JWT\Signer\Key;
use Lcobucci\JWT\Signer\Hmac\Sha256;
use League\OAuth2\Client\Provider\Apple;
use League\OAuth2\Client\Provider\AppleResourceOwner;
use League\OAuth2\Client\Test\KeyDumpSigner;
use League\OAuth2\Client\Token\AccessToken;
use League\OAuth2\Client\Token\AppleAccessToken;
use League\OAuth2\Client\Tool\QueryBuilderTrait;
use PHPUnit\Framework\TestCase;
use Mockery as m;
class AppleTest extends TestCase
{
use QueryBuilderTrait;
/**
* @return Apple
*/
private function getProvider()
{
return new Apple(['clientId' => 'mock.example', 'teamId' => 'mock.team.id', 'keyFileId' => 'mock.file.id', 'keyFilePath' => __DIR__ . '/p256-private-key.p8', 'redirectUri' => 'none']);
return new Apple([
'clientId' => 'mock.example',
'teamId' => 'mock.team.id',
'keyFileId' => 'mock.file.id',
'keyFilePath' => __DIR__ . '/p256-private-key.p8',
'redirectUri' => 'none'
]);
}
public function testMissingTeamIdDuringInstantiationThrowsException()
{
$this->expectException('InvalidArgumentException');
new Apple(['clientId' => 'mock.example', 'keyFileId' => 'mock.file.id', 'keyFilePath' => __DIR__ . '/p256-private-key.p8', 'redirectUri' => 'none']);
new Apple([
'clientId' => 'mock.example',
'keyFileId' => 'mock.file.id',
'keyFilePath' => __DIR__ . '/p256-private-key.p8',
'redirectUri' => 'none'
]);
}
public function testMissingKeyFileIdDuringInstantiationThrowsException()
{
$this->expectException('InvalidArgumentException');
new Apple(['clientId' => 'mock.example', 'teamId' => 'mock.team.id', 'keyFilePath' => __DIR__ . '/p256-private-key.p8', 'redirectUri' => 'none']);
new Apple([
'clientId' => 'mock.example',
'teamId' => 'mock.team.id',
'keyFilePath' => __DIR__ . '/p256-private-key.p8',
'redirectUri' => 'none'
]);
}
public function testMissingKeyFilePathDuringInstantiationThrowsException()
{
$this->expectException('InvalidArgumentException');
new Apple(['clientId' => 'mock.example', 'teamId' => 'mock.team.id', 'keyFileId' => 'mock.file.id', 'redirectUri' => 'none']);
new Apple([
'clientId' => 'mock.example',
'teamId' => 'mock.team.id',
'keyFileId' => 'mock.file.id',
'redirectUri' => 'none'
]);
}
public function testMissingKeyDuringInstantiationThrowsException()
{
$this->expectException('InvalidArgumentException');
$this->getProvider()->getLocalKey();
}
public function testAuthorizationUrl()
{
$provider = $this->getProvider();
$url = $provider->getAuthorizationUrl();
$uri = parse_url($url);
parse_str($uri['query'], $query);
$this->assertArrayHasKey('client_id', $query);
$this->assertArrayHasKey('redirect_uri', $query);
$this->assertArrayHasKey('state', $query);
@@ -59,6 +88,7 @@ class AppleTest extends TestCase
$this->assertArrayHasKey('response_mode', $query);
$this->assertNotNull($provider->getState());
}
public function testScopes()
{
$provider = $this->getProvider();
@@ -69,79 +99,170 @@ class AppleTest extends TestCase
$encodedScope = $this->buildQueryString($query);
$this->assertNotFalse(strpos($url, $encodedScope));
}
public function testGetAuthorizationUrl()
{
$provider = $this->getProvider();
$url = $provider->getAuthorizationUrl();
$uri = parse_url($url);
$this->assertEquals('/auth/authorize', $uri['path']);
}
public function testGetBaseAccessTokenUrl()
{
$provider = $this->getProvider();
$params = [];
$url = $provider->getBaseAccessTokenUrl($params);
$uri = parse_url($url);
$this->assertEquals('/auth/token', $uri['path']);
}
public function testGetAccessToken()
{
$this->expectException('UnexpectedValueException');
$provider = new TestApple(['clientId' => 'mock.example', 'teamId' => 'mock.team.id', 'keyFileId' => 'mock.file.id', 'keyFilePath' => __DIR__ . '/../../resources/p256-private-key.p8', 'redirectUri' => 'none']);
$provider = new TestApple([
'clientId' => 'mock.example',
'teamId' => 'mock.team.id',
'keyFileId' => 'mock.file.id',
'keyFilePath' => __DIR__ . '/../../resources/p256-private-key.p8',
'redirectUri' => 'none'
]);
$provider = m::mock($provider);
$configuration = Configuration::forSymmetricSigner(new KeyDumpSigner(), Key\InMemory::plainText('private'));
$configuration = Configuration::forSymmetricSigner(
new KeyDumpSigner(),
Key\InMemory::plainText('private')
);
$time = new \DateTimeImmutable();
$expiresAt = $time->modify('+1 Hour');
$token = $configuration->builder()->issuedBy('test-team-id')->permittedFor('https://appleid.apple.com')->issuedAt($time)->expiresAt($expiresAt)->relatedTo('test-client')->withHeader('alg', 'RS256')->withHeader('kid', 'test')->getToken($configuration->signer(), $configuration->signingKey());
$token = $configuration->builder()
->issuedBy('test-team-id')
->permittedFor('https://appleid.apple.com')
->issuedAt($time)
->expiresAt($expiresAt)
->relatedTo('test-client')
->withHeader('alg', 'RS256')
->withHeader('kid', 'test')
->getToken($configuration->signer(), $configuration->signingKey());
$client = m::mock(ClientInterface::class);
$client->shouldReceive('request')->times(1)->andReturn(new Response(200, [], file_get_contents('https://appleid.apple.com/auth/keys')));
$client->shouldReceive('send')->times(1)->andReturn(new Response(200, [], json_encode(['access_token' => 'aad897dee58fe4f66bf220c181adaf82b.0.mrwxq.hmiE0djj1vJqoNisKmF-pA', 'token_type' => 'Bearer', 'expires_in' => 3600, 'refresh_token' => 'r4a6e8b9c50104b78bc86b0d2649353fa.0.mrwxq.54joUj40j0cpuMANRtRjfg', 'id_token' => $token->toString()])));
$client->shouldReceive('request')
->times(1)
->andReturn(new Response(200, [], file_get_contents('https://appleid.apple.com/auth/keys')));
$client->shouldReceive('send')
->times(1)
->andReturn(new Response(200, [], json_encode([
'access_token' => 'aad897dee58fe4f66bf220c181adaf82b.0.mrwxq.hmiE0djj1vJqoNisKmF-pA',
'token_type' => 'Bearer',
'expires_in' => 3600,
'refresh_token' => 'r4a6e8b9c50104b78bc86b0d2649353fa.0.mrwxq.54joUj40j0cpuMANRtRjfg',
'id_token' => $token->toString()
])));
$provider->setHttpClient($client);
$provider->getAccessToken('authorization_code', ['code' => 'hello-world']);
$provider->getAccessToken('authorization_code', [
'code' => 'hello-world'
]);
}
public function testGetAccessTokenFailedBecauseAppleHasError()
{
$this->expectException('Exception');
$this->expectExceptionMessage('Got no data within "id_token"!');
$provider = new TestApple(['clientId' => 'mock.example', 'teamId' => 'mock.team.id', 'keyFileId' => 'mock.file.id', 'keyFilePath' => __DIR__ . '/../../resources/p256-private-key.p8', 'redirectUri' => 'none']);
$provider = new TestApple([
'clientId' => 'mock.example',
'teamId' => 'mock.team.id',
'keyFileId' => 'mock.file.id',
'keyFilePath' => __DIR__ . '/../../resources/p256-private-key.p8',
'redirectUri' => 'none'
]);
$provider = m::mock($provider);
$client = m::mock(ClientInterface::class);
$client->shouldReceive('request')->times(1)->andReturn(new Response(500, [], 'Internal Server Error'));
$client->shouldReceive('send')->times(1)->andReturn(new Response(200, [], json_encode(['access_token' => 'aad897dee58fe4f66bf220c181adaf82b.0.mrwxq.hmiE0djj1vJqoNisKmF-pA', 'token_type' => 'Bearer', 'expires_in' => 3600, 'refresh_token' => 'r4a6e8b9c50104b78bc86b0d2649353fa.0.mrwxq.54joUj40j0cpuMANRtRjfg', 'id_token' => 'abc'])));
$client->shouldReceive('request')
->times(1)
->andReturn(new Response(500, [], 'Internal Server Error'));
$client->shouldReceive('send')
->times(1)
->andReturn(new Response(200, [], json_encode([
'access_token' => 'aad897dee58fe4f66bf220c181adaf82b.0.mrwxq.hmiE0djj1vJqoNisKmF-pA',
'token_type' => 'Bearer',
'expires_in' => 3600,
'refresh_token' => 'r4a6e8b9c50104b78bc86b0d2649353fa.0.mrwxq.54joUj40j0cpuMANRtRjfg',
'id_token' => 'abc'
])));
$provider->setHttpClient($client);
$provider->getAccessToken('authorization_code', ['code' => 'hello-world']);
$provider->getAccessToken('authorization_code', [
'code' => 'hello-world'
]);
}
public function testRevokeAccessToken()
{
$provider = new TestApple(['clientId' => 'mock.example', 'teamId' => 'mock.team.id', 'keyFileId' => 'mock.file.id', 'keyFilePath' => __DIR__ . '/../../resources/p256-private-key.p8', 'redirectUri' => 'none']);
$provider = new TestApple([
'clientId' => 'mock.example',
'teamId' => 'mock.team.id',
'keyFileId' => 'mock.file.id',
'keyFilePath' => __DIR__ . '/../../resources/p256-private-key.p8',
'redirectUri' => 'none'
]);
$provider = m::mock($provider);
$client = m::mock(ClientInterface::class);
$client->shouldReceive('send')->times(1)->andReturn(new Response(200, [], json_encode([])));
$client->shouldReceive('send')
->times(1)
->andReturn(new Response(200, [], json_encode([])));
$provider->setHttpClient($client);
$this->assertEmpty($provider->revokeAccessToken('hello-world', 'access_token'));
}
public function testRevokeAccessTokenFailedBecauseAppleHasError()
{
$this->expectException('Exception');
$this->expectExceptionMessage('invalid_request');
$provider = new TestApple(['clientId' => 'mock.example', 'teamId' => 'mock.team.id', 'keyFileId' => 'mock.file.id', 'keyFilePath' => __DIR__ . '/../../resources/p256-private-key.p8', 'redirectUri' => 'none']);
$provider = new TestApple([
'clientId' => 'mock.example',
'teamId' => 'mock.team.id',
'keyFileId' => 'mock.file.id',
'keyFilePath' => __DIR__ . '/../../resources/p256-private-key.p8',
'redirectUri' => 'none'
]);
$provider = m::mock($provider);
$client = m::mock(ClientInterface::class);
$client->shouldReceive('send')->times(1)->andReturn(new Response(400, [], json_encode(['error' => 'invalid_request'])));
$client->shouldReceive('send')
->times(1)
->andReturn(new Response(400, [], json_encode(['error' => 'invalid_request'])));
$provider->setHttpClient($client);
$provider->revokeAccessToken('hello-world');
}
public function testFetchingOwnerDetails()
{
$provider = $this->getProvider();
$class = new \ReflectionClass($provider);
$method = $class->getMethod('fetchResourceOwnerDetails');
$method->setAccessible(\true);
$arr = ['name' => 'John Doe'];
$method->setAccessible(true);
$arr = [
'name' => 'John Doe'
];
$_POST['user'] = json_encode($arr);
$data = $method->invokeArgs($provider, [new AccessToken(['access_token' => 'hello'])]);
$this->assertEquals($arr, $data);
}
/**
* @see https://github.com/patrickbussmann/oauth2-apple/issues/12
*/
@@ -150,54 +271,92 @@ class AppleTest extends TestCase
$provider = $this->getProvider();
$class = new \ReflectionClass($provider);
$method = $class->getMethod('fetchResourceOwnerDetails');
$method->setAccessible(\true);
$method->setAccessible(true);
$_POST['user'] = '';
$data = $method->invokeArgs($provider, [new AccessToken(['access_token' => 'hello'])]);
$this->assertEquals([], $data);
}
public function testNotImplementedGetResourceOwnerDetailsUrl()
{
$this->expectException('Exception');
$provider = $this->getProvider();
$provider->getResourceOwnerDetailsUrl(new AccessToken(['access_token' => 'hello']));
}
public function testCheckResponse()
{
$this->expectException('Pshowsso\Scope68f5e85e9608b\League\OAuth2\Client\Provider\Exception\AppleAccessDeniedException');
$this->expectException('\League\OAuth2\Client\Provider\Exception\AppleAccessDeniedException');
$this->expectExceptionMessage('invalid_client');
$provider = $this->getProvider();
$class = new \ReflectionClass($provider);
$method = $class->getMethod('checkResponse');
$method->setAccessible(\true);
$method->invokeArgs($provider, [new Response(400, []), ['error' => 'invalid_client', 'code' => 400]]);
$method->setAccessible(true);
$method->invokeArgs($provider, [new Response(400, []), [
'error' => 'invalid_client',
'code' => 400
]]);
}
public function testResourceToArrayHasAttributes()
{
$provider = $this->getProvider();
$class = new \ReflectionClass($provider);
$method = $class->getMethod('createResourceOwner');
$method->setAccessible(\true);
$method->setAccessible(true);
/** @var AppleResourceOwner $data */
$data = $method->invokeArgs($provider, [[
'email' => 'john@doe.com',
// <- Fake E-Mail from user input
'name' => ['firstName' => 'John', 'lastName' => 'Doe'],
], new AccessToken(['access_token' => 'hello', 'email' => 'john@doe.de', 'resource_owner_id' => '123.4.567'])]);
$expectedArray = ['email' => 'john@doe.de', 'sub' => '123.4.567', 'name' => ['firstName' => 'John', 'lastName' => 'Doe'], 'isPrivateEmail' => null];
$data = $method->invokeArgs($provider, [
[
'email' => 'john@doe.com',// <- Fake E-Mail from user input
'name' => [
'firstName' => 'John',
'lastName' => 'Doe'
]
],
new AccessToken([
'access_token' => 'hello',
'email' => 'john@doe.de',
'resource_owner_id' => '123.4.567'
])
]);
$expectedArray = [
'email' => 'john@doe.de',
'sub' => '123.4.567',
'name' => [
'firstName' => 'John',
'lastName' => 'Doe'
],
'isPrivateEmail' => null
];
$this->assertEquals($expectedArray, $data->toArray());
}
public function testCreationOfResourceOwnerWithName()
{
$provider = $this->getProvider();
$class = new \ReflectionClass($provider);
$method = $class->getMethod('createResourceOwner');
$method->setAccessible(\true);
$method->setAccessible(true);
/** @var AppleResourceOwner $data */
$data = $method->invokeArgs($provider, [[
'email' => 'john@doe.com',
// <- Fake E-Mail from user input
'name' => ['firstName' => 'John', 'lastName' => 'Doe'],
], new AccessToken(['access_token' => 'hello', 'email' => 'john@doe.de', 'resource_owner_id' => '123.4.567'])]);
$data = $method->invokeArgs($provider, [
[
'email' => 'john@doe.com',// <- Fake E-Mail from user input
'name' => [
'firstName' => 'John',
'lastName' => 'Doe'
]
],
new AccessToken([
'access_token' => 'hello',
'email' => 'john@doe.de',
'resource_owner_id' => '123.4.567'
])
]);
$this->assertEquals('john@doe.de', $data->getEmail());
$this->assertEquals('Doe', $data->getLastName());
$this->assertEquals('John', $data->getFirstName());
@@ -205,22 +364,33 @@ class AppleTest extends TestCase
$this->assertFalse($data->isPrivateEmail());
$this->assertArrayHasKey('name', $data->toArray());
}
public function testCreationOfResourceOwnerWithoutName()
{
$provider = $this->getProvider();
$class = new \ReflectionClass($provider);
$method = $class->getMethod('createResourceOwner');
$method->setAccessible(\true);
$method->setAccessible(true);
/** @var AppleResourceOwner $data */
$data = $method->invokeArgs($provider, [[], new AccessToken(['access_token' => 'hello', 'email' => 'john@doe.de', 'resource_owner_id' => '123.4.567'])]);
$data = $method->invokeArgs($provider, [
[],
new AccessToken([
'access_token' => 'hello',
'email' => 'john@doe.de',
'resource_owner_id' => '123.4.567'
])
]);
$this->assertEquals('john@doe.de', $data->getEmail());
$this->assertNull($data->getLastName());
$this->assertNull($data->getFirstName());
}
public function testGetConfiguration()
{
$provider = m::mock(Apple::class)->makePartial();
$provider->shouldReceive('getLocalKey')->andReturn(m::mock(Key::class));
$this->assertInstanceOf(Configuration::class, $provider->getConfiguration());
}
}

View File

@@ -1,11 +1,12 @@
<?php
namespace Pshowsso\Scope68f5e85e9608b\League\OAuth2\Client\Test\Provider;
namespace League\OAuth2\Client\Test\Provider;
use Lcobucci\JWT\Configuration;
use Lcobucci\JWT\Signer\Key\InMemory;
use League\OAuth2\Client\Provider\Apple;
use League\OAuth2\Client\Test\KeyDumpSigner;
use Pshowsso\Scope68f5e85e9608b\Lcobucci\JWT\Configuration;
use Pshowsso\Scope68f5e85e9608b\Lcobucci\JWT\Signer\Key\InMemory;
use Pshowsso\Scope68f5e85e9608b\League\OAuth2\Client\Provider\Apple;
use Pshowsso\Scope68f5e85e9608b\League\OAuth2\Client\Test\KeyDumpSigner;
/**
* Class TestApple
* @package League\OAuth2\Client\Test\Provider
@@ -18,8 +19,12 @@ class TestApple extends Apple
*/
public function getConfiguration()
{
return Configuration::forSymmetricSigner(new KeyDumpSigner(), InMemory::plainText('private'));
return Configuration::forSymmetricSigner(
new KeyDumpSigner(),
InMemory::plainText('private')
);
}
/**
* {@inheritDoc}
*/

View File

@@ -1,11 +1,12 @@
<?php
namespace Pshowsso\Scope68f5e85e9608b\League\OAuth2\Client\Test\Token;
namespace League\OAuth2\Client\Test\Token;
use Pshowsso\Scope68f5e85e9608b\Firebase\JWT\Key;
use Pshowsso\Scope68f5e85e9608b\League\OAuth2\Client\Token\AppleAccessToken;
use Firebase\JWT\Key;
use League\OAuth2\Client\Token\AppleAccessToken;
use PHPUnit\Framework\TestCase;
use Mockery as m;
class AppleAccessTokenTest extends TestCase
{
/**
@@ -15,26 +16,55 @@ class AppleAccessTokenTest extends TestCase
public function testCreatingAccessToken()
{
$externalJWTMock = m::mock('overload:Firebase\JWT\JWT');
$externalJWTMock->shouldReceive('decode')->with('something', 'examplekey')->once()->andReturn(['sub' => '123.abc.123', 'email_verified' => \true, 'email' => 'john@doe.com', 'is_private_email' => \true]);
$accessToken = new AppleAccessToken(['examplekey'], ['access_token' => 'access_token', 'token_type' => 'Bearer', 'expires_in' => 3600, 'refresh_token' => 'abc.0.def', 'id_token' => 'something']);
$externalJWTMock->shouldReceive('decode')
->with('something', 'examplekey')
->once()
->andReturn([
'sub' => '123.abc.123',
'email_verified' => true,
'email' => 'john@doe.com',
'is_private_email' => true
]);
$accessToken = new AppleAccessToken(['examplekey'], [
'access_token' => 'access_token',
'token_type' => 'Bearer',
'expires_in' => 3600,
'refresh_token' => 'abc.0.def',
'id_token' => 'something'
]);
$this->assertEquals('something', $accessToken->getIdToken());
$this->assertEquals('123.abc.123', $accessToken->getResourceOwnerId());
$this->assertEquals('access_token', $accessToken->getToken());
$this->assertEquals('john@doe.com', $accessToken->getEmail());
$this->assertTrue($accessToken->isPrivateEmail());
$this->assertTrue(\true);
$this->assertTrue(true);
}
public function testCreateFailsBecauseNoIdTokenIsSet()
{
$this->expectException('\InvalidArgumentException');
$this->expectExceptionMessage('Required option not passed: "id_token"');
new AppleAccessToken(['examplekey'], ['access_token' => 'access_token', 'token_type' => 'Bearer', 'expires_in' => 3600, 'refresh_token' => 'abc.0.def']);
new AppleAccessToken(['examplekey'], [
'access_token' => 'access_token',
'token_type' => 'Bearer',
'expires_in' => 3600,
'refresh_token' => 'abc.0.def'
]);
}
public function testCreatingRefreshToken()
{
$refreshToken = new AppleAccessToken([], ['access_token' => 'access_token', 'token_type' => 'Bearer', 'expires_in' => 3600]);
$refreshToken = new AppleAccessToken([], [
'access_token' => 'access_token',
'token_type' => 'Bearer',
'expires_in' => 3600
]);
$this->assertEquals('access_token', $refreshToken->getToken());
}
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
@@ -43,8 +73,19 @@ class AppleAccessTokenTest extends TestCase
{
$this->expectException('\Exception');
$this->expectExceptionMessage('Got no data within "id_token"!');
$externalJWTMock = m::mock('overload:Firebase\JWT\JWT');
$externalJWTMock->shouldReceive('decode')->with('something', 'examplekey')->once()->andReturnNull();
new AppleAccessToken(['examplekey'], ['access_token' => 'access_token', 'token_type' => 'Bearer', 'expires_in' => 3600, 'refresh_token' => 'abc.0.def', 'id_token' => 'something']);
$externalJWTMock->shouldReceive('decode')
->with('something', 'examplekey')
->once()
->andReturnNull();
new AppleAccessToken(['examplekey'], [
'access_token' => 'access_token',
'token_type' => 'Bearer',
'expires_in' => 3600,
'refresh_token' => 'abc.0.def',
'id_token' => 'something'
]);
}
}