Skip to content

Commit

Permalink
Increased library compatibility and fixed all tests
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickbussmann committed Jan 17, 2021
1 parent d649df8 commit 31c61d3
Show file tree
Hide file tree
Showing 8 changed files with 251 additions and 260 deletions.
12 changes: 8 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ matrix:
- php: 7.0
- php: 7.1
- php: 7.2
- php: 7.3
- php: 7.4
- php: 8.0
- php: nightly
- php: hhvm-3.6
sudo: required
Expand Down Expand Up @@ -35,8 +38,6 @@ matrix:
- php: hhvm-3.12
- php: hhvm-3.15
- php: hhvm-nightly
- php: 7.3
- php: 7.4

before_script:
- travis_retry composer self-update
Expand All @@ -48,5 +49,8 @@ script:
- ./vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover

after_script:
- if [ "$TRAVIS_PHP_VERSION" == "7.1" ]; then wget https://scrutinizer-ci.com/ocular.phar; fi
- if [ "$TRAVIS_PHP_VERSION" == "7.1" ]; then php ocular.phar code-coverage:upload --format=php-clover coverage.clover; fi
- if [ "$TRAVIS_PHP_VERSION" == "7.4" ]; then wget https://scrutinizer-ci.com/ocular.phar; fi
- if [ "$TRAVIS_PHP_VERSION" == "7.4" ]; then php ocular.phar code-coverage:upload --format=php-clover coverage.clover; fi

after_success:
- bash <(curl -s https://codecov.io/bash)
29 changes: 29 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
codecov:
require_ci_to_pass: yes

coverage:
precision: 2
round: down
range: "70...100"
status:
project:
default:
target: auto
threshold: 0%
patch:
default:
target: auto
threshold: 0%

parsers:
gcov:
branch_detection:
conditional: yes
loop: yes
method: no
macro: no

comment:
layout: "reach,diff,flags,tree"
behavior: default
require_changes: false
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
"league/oauth2-client": "^2.0",
"ext-json": "*",
"firebase/php-jwt": "^5.2",
"lcobucci/jwt": "^3.4.1"
"lcobucci/jwt": "^3.4 || ^4.0"
},
"require-dev": {
"phpunit/phpunit": "^4.8|^7.5",
"mockery/mockery": "~1.3.3",
"squizlabs/php_codesniffer": "~2.0",
"phpunit/phpunit": "^5.7 || ^6.0 || ^9.3",
"mockery/mockery": "^1.3",
"squizlabs/php_codesniffer": "^2.3 || ^3.0",
"ext-json": "*"
},
"autoload": {
Expand Down
52 changes: 20 additions & 32 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,34 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
>
<logging>
<log type="coverage-html"
target="./build/coverage/html"
lowUpperBound="35"
highLowerBound="70"/>
<log type="coverage-clover"
target="./build/coverage/log/coverage.xml"/>
</logging>
<testsuites>
<testsuite name="Package Test Suite">
<directory suffix=".php">./test/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">./</directory>
<exclude>
<directory suffix=".php">./vendor</directory>
<directory suffix=".php">./test</directory>
</exclude>
</whitelist>
</filter>
<phpunit xmlns:xsi="http:https://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" backupStaticAttributes="false" bootstrap="vendor/autoload.php" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<include>
<directory suffix=".php">./</directory>
</include>
<exclude>
<directory suffix=".php">./vendor</directory>
<directory suffix=".php">./test</directory>
</exclude>
<report>
<clover outputFile="./build/coverage/log/coverage.xml"/>
<html outputDirectory="./build/coverage/html" lowUpperBound="35" highLowerBound="70"/>
</report>
</coverage>
<logging/>
<testsuites>
<testsuite name="Package Test Suite">
<directory suffix=".php">./test/</directory>
</testsuite>
</testsuites>
</phpunit>
55 changes: 18 additions & 37 deletions src/Provider/Apple.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@

use Exception;
use InvalidArgumentException;
use Lcobucci\JWT\Builder;
use Lcobucci\JWT\Signer\Ecdsa\Sha256;
use Lcobucci\JWT\Configuration;
use Lcobucci\JWT\Signer\Key\LocalFileReference;
use Lcobucci\JWT\Signer;
use Lcobucci\JWT\Signer\Key;
use DateTimeImmutable;

use League\OAuth2\Client\Grant\AbstractGrant;
use League\OAuth2\Client\Provider\Exception\AppleAccessDeniedException;
use League\OAuth2\Client\Token\AccessToken;
Expand Down Expand Up @@ -210,61 +209,43 @@ protected function createResourceOwner(array $response, AccessToken $token)
*/
public function getAccessToken($grant, array $options = [])
{
if(class_exists('\Lcobucci\JWT\Configuration')){
return $this->getAccessToken34($grant,$options);
}

$signer = new Sha256();
$configuration = $this->getConfiguration();
$time = new \DateTimeImmutable();
$expiresAt = $time->modify('+1 Hour');

$token = (new Builder())
$token = $configuration->builder()
->issuedBy($this->teamId)
->permittedFor('https://appleid.apple.com')
->issuedAt($time->getTimestamp())
->expiresAt($expiresAt->getTimestamp())
->issuedAt($time)
->expiresAt($expiresAt)
->relatedTo($this->clientId)
->withHeader('alg', 'ES256')
->withHeader('kid', $this->keyFileId)
->getToken($signer, $this->getLocalKey());
->getToken($configuration->signer(), $configuration->signingKey());

$options += [
'client_secret' => (string) $token
'client_secret' => $token->toString()
];

return parent::getAccessToken($grant, $options);
}

private function getAccessToken34($grant, array $options = [])
/**
* @return Configuration
*/
public function getConfiguration()
{
$signer = new Sha256();
$now = new DateTimeImmutable();
$key = Key\LocalFileReference::file($this->keyFilePath);
$config = \Lcobucci\JWT\Configuration::forSymmetricSigner($signer, $key);

$token = $config->builder()
->issuedBy($this->teamId)
->permittedFor('https://appleid.apple.com')
->issuedAt($now)
->expiresAt($now->modify('+10 minute'))
->relatedTo($this->clientId)
->withHeader('alg', 'ES256')
->withHeader('kid', $this->keyFileId)
->getToken($config->signer(), $this->getLocalKey());

$options += [
'client_secret' => (string) $token
];

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


/**
* @return Key
*/
public function getLocalKey()
{
return new Key('file:https://' . $this->keyFilePath);
return LocalFileReference::file($this->keyFilePath);
}
}
Loading

0 comments on commit 31c61d3

Please sign in to comment.