diff --git a/README.md b/README.md index 2be4138..e901de6 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Zend Authentication adapter for Auth0 ## Requirements * PHP 7.0+ -* [riskio/oauth2-auth0 ^0.1](https://github.com/RiskioFr/oauth2-auth0) +* [riskio/oauth2-auth0 ^2.0](https://github.com/RiskioFr/oauth2-auth0) * [zendframework/zend-authentication ^2.5](https://github.com/zendframework/zend-authentication) ## Installation diff --git a/composer.json b/composer.json index 54e3972..ca81798 100755 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ ], "require": { "php": "^7.0", - "riskio/oauth2-auth0": "~0.1", + "riskio/oauth2-auth0": "~2.0", "zendframework/zend-authentication": "~2.5" }, "require-dev": { diff --git a/src/Adapter.php b/src/Adapter.php index bbeb134..1fdf4b1 100644 --- a/src/Adapter.php +++ b/src/Adapter.php @@ -3,14 +3,14 @@ use Exception; use League\OAuth2\Client\Grant\AuthorizationCode; -use League\OAuth2\Client\Provider\ProviderInterface; +use League\OAuth2\Client\Provider\AbstractProvider; use League\OAuth2\Client\Token\AccessToken; use Zend\Authentication\Adapter\AdapterInterface; class Adapter implements AdapterInterface { /** - * @var ProviderInterface + * @var AbstractProvider */ private $oauthProvider; @@ -19,7 +19,7 @@ class Adapter implements AdapterInterface */ private $code; - public function __construct(ProviderInterface $oauthProvider) + public function __construct(AbstractProvider $oauthProvider) { $this->oauthProvider = $oauthProvider; } @@ -47,8 +47,7 @@ public function authenticate() : OAuth2Result try { $token = $this->getAccessToken(); - /* @var $user \League\OAuth2\Client\Entity\User */ - $user = $this->oauthProvider->getUserDetails($token); + $user = $this->oauthProvider->getResourceOwner($token); if (!$user) { return new OAuth2Result( OAuth2Result::FAILURE_IDENTITY_NOT_FOUND, diff --git a/tests/AdapterTest.php b/tests/AdapterTest.php index bd23081..4816cef 100644 --- a/tests/AdapterTest.php +++ b/tests/AdapterTest.php @@ -1,9 +1,9 @@ prophesize(AccessToken::class); - $user = new User(); - $providerMock = $this->getOauthProvider($token, $user); + $accessToken = 'abcdef'; + $resourceOwnerId = 123; + $code = 123; + + $token = new AccessToken(['access_token' => $accessToken]); + $resourceOwner = $this->createResourceOwner($resourceOwnerId); + $providerMock = $this->getOauthProvider($token, $resourceOwner); $adapter = new Adapter($providerMock->reveal()); $adapter->setCode($code); $result = $adapter->authenticate(); - $this->assertInstanceOf(OAuth2Result::class, $result); - $this->assertEquals(OAuth2Result::SUCCESS, $result->getCode()); - $this->assertInstanceOf(AccessToken::class, $result->getAccessToken()); - $this->assertEquals($user, $result->getIdentity()); + self::assertInstanceOf(OAuth2Result::class, $result); + self::assertSame(OAuth2Result::SUCCESS, $result->getCode()); + self::assertSame($token, $result->getAccessToken()); + self::assertSame($resourceOwner, $result->getIdentity()); } - private function getOauthProvider($token, $user) + private function getOauthProvider($token, $resourceOwner) { - $providerMock = $this->prophesize(ProviderInterface::class); + $providerMock = $this->prophesize(AbstractProvider::class); $providerMock ->getAccessToken(Argument::type(AuthorizationCode::class), Argument::type('array')) - ->willReturn($token->reveal()); - $providerMock->getUserDetails(Argument::type(AccessToken::class))->willReturn($user); + ->willReturn($token); + $providerMock + ->getResourceOwner($token) + ->willReturn($resourceOwner); return $providerMock; } + + private function createResourceOwner(int $resourceOwnerId) : GenericResourceOwner + { + return new GenericResourceOwner([], $resourceOwnerId); + } }