From f6bfe604db1e984aa1d25b2c76f5372036c84bdc Mon Sep 17 00:00:00 2001 From: Ujjwal Ojha Date: Fri, 22 Aug 2014 14:28:10 +0545 Subject: [PATCH 01/12] Update README.md --- README.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/README.md b/README.md index 56c8dbc..4c55e79 100644 --- a/README.md +++ b/README.md @@ -59,16 +59,13 @@ return [ 'ht_oauth_service_client' => [ 'create_user_callable' => function(\League\OAuth2\Client\Entity\User $userDetails) { $user = ......; - $userProvider = new \Hrevert\OauthClient\Entity\UserProvider(); $userProvider->setUser($user); - return $userProvider; // or just $user = ......; - return $user; } ] From 1f369502894c4c07c54112e600e108297422a30e Mon Sep 17 00:00:00 2001 From: Ujjwal Ojha Date: Fri, 22 Aug 2014 14:35:52 +0545 Subject: [PATCH 02/12] Added badges --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index 4c55e79..1cb4d6a 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,10 @@ HtOauth\Server\ClientModule ====================== A Zend Framework 2 module which provides custom grant for [zfr-oauth2-server](https://github.com/zf-fr/zfr-oauth2-server) to authenticate users via third party applications like facebook, google etc. +[![Master Branch Build Status](https://api.travis-ci.org/hrevert/ht-oauth-server-client-module.png?branch=master)](http://travis-ci.org/hrevert/ht-oauth-server-client-module) +[![Latest Stable Version](https://poser.pugx.org/hrevert/ht-oauth-server-client-module/version.svg)](https://packagist.org/packages/hrevert/ht-oauth-server-client-module) +[![Latest Unstable Version](https://poser.pugx.org/hrevert/ht-oauth-server-client-module/v/unstable.svg)](//packagist.org/packages/hrevert/ht-oauth-server-client-module) [![Total Downloads](https://poser.pugx.org/hrevert/ht-oauth-server-client-module/downloads.svg)](https://packagist.org/packages/hrevert/ht-oauth-server-client-module) + ## Installation * Add `"hrevert/ht-oauth-server-client-module": "dev-master"` to composer.json and run `php composer.phar update`. * Enabled the following modules in `config/application.config.php`. @@ -59,13 +63,16 @@ return [ 'ht_oauth_service_client' => [ 'create_user_callable' => function(\League\OAuth2\Client\Entity\User $userDetails) { $user = ......; + $userProvider = new \Hrevert\OauthClient\Entity\UserProvider(); $userProvider->setUser($user); + return $userProvider; // or just $user = ......; + return $user; } ] From 1adcb505d3a6fc4a4a9b615a394dc45f7d76929c Mon Sep 17 00:00:00 2001 From: Ujjwal Ojha Date: Fri, 22 Aug 2014 14:54:20 +0545 Subject: [PATCH 03/12] Remove mininum-stability option --- composer.json | 1 - 1 file changed, 1 deletion(-) diff --git a/composer.json b/composer.json index 6bb2732..b6d4574 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,6 @@ "email": "info@hrevert.com" } ], - "minimum-stability" :"dev", "require": { "php": ">=5.4", "hrevert/ht-oauth-client-module": "0.0.*", From 46e50a9b5ca874a851643ddbce15e85ce79105e2 Mon Sep 17 00:00:00 2001 From: Ujjwal Ojha Date: Fri, 22 Aug 2014 14:58:54 +0545 Subject: [PATCH 04/12] Added note on name --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 1cb4d6a..228d337 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,9 @@ A Zend Framework 2 module which provides custom grant for [zfr-oauth2-server](ht [![Latest Stable Version](https://poser.pugx.org/hrevert/ht-oauth-server-client-module/version.svg)](https://packagist.org/packages/hrevert/ht-oauth-server-client-module) [![Latest Unstable Version](https://poser.pugx.org/hrevert/ht-oauth-server-client-module/v/unstable.svg)](//packagist.org/packages/hrevert/ht-oauth-server-client-module) [![Total Downloads](https://poser.pugx.org/hrevert/ht-oauth-server-client-module/downloads.svg)](https://packagist.org/packages/hrevert/ht-oauth-server-client-module) +### What's with the name? +The module provides a grant for a oauth2 server and it is also a client for oauth2 servers of facebook, google etc. So, it is named as server as well as client. + ## Installation * Add `"hrevert/ht-oauth-server-client-module": "dev-master"` to composer.json and run `php composer.phar update`. * Enabled the following modules in `config/application.config.php`. From 045bc7aff2996af7ba72b97b4c30b33025dc7d80 Mon Sep 17 00:00:00 2001 From: Ujjwal Ojha Date: Fri, 22 Aug 2014 15:10:09 +0545 Subject: [PATCH 05/12] Fix compatibility with latest stable oauth2-client library, fixes tests --- README.md | 2 +- src/Grant/Oauth2Client.php | 2 +- tests/src/Grant/Oauth2ClientTest.php | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 228d337..73fbf7d 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,7 @@ To automatically create a new user, you need to specify a callable for creating return [ 'ht_oauth_service_client' => [ - 'create_user_callable' => function(\League\OAuth2\Client\Entity\User $userDetails) { + 'create_user_callable' => function(\League\OAuth2\Client\Provider\User $userDetails) { $user = ......; $userProvider = new \Hrevert\OauthClient\Entity\UserProvider(); diff --git a/src/Grant/Oauth2Client.php b/src/Grant/Oauth2Client.php index 5041823..6f12abc 100644 --- a/src/Grant/Oauth2Client.php +++ b/src/Grant/Oauth2Client.php @@ -116,7 +116,7 @@ public function createTokenResponse(HttpRequest $request, Client $client = null, throw OAuth2Exception::invalidRequest(sprintf('Provider authorization code is invalid')); } - /** @var \League\OAuth2\Client\Entity\User */ + /** @var \League\OAuth2\Client\Provider\User */ $userDetails = $providerClient->getUserDetails($providerAccessToken); // access token is valid diff --git a/tests/src/Grant/Oauth2ClientTest.php b/tests/src/Grant/Oauth2ClientTest.php index 9a9ec70..2e5e2b6 100644 --- a/tests/src/Grant/Oauth2ClientTest.php +++ b/tests/src/Grant/Oauth2ClientTest.php @@ -7,7 +7,7 @@ use DateTime; use ZfrOAuth2\Server\Entity\AccessToken; use Hrevert\OauthClient\Model\UserProviderInterface; -use League\OAuth2\Client\Entity\User as ProviderUser; +use League\OAuth2\Client\Provider\User as ProviderUser; use ZfrOAuth2\Server\Entity\Client; use ZfrOAuth2\Server\Entity\RefreshToken; use ZfrOAuth2\Server\Grant\RefreshTokenGrant; @@ -144,7 +144,7 @@ public function testGetExceptionWhenProviderAuthorizationCodeIsInvalid() ->with('facebook') ->will($this->returnValue($provider)); - $providerClient = $this->getMock('League\OAuth2\Client\Provider\ProviderInterface'); + $providerClient = $this->getMock('League\OAuth2\Client\Provider\IdentityProvider'); $providerClients->expects($this->once()) ->method('get') @@ -203,7 +203,7 @@ public function testCanCreateTokenResponse($hasRefreshGrant, UserProviderInterfa ->with('facebook') ->will($this->returnValue($provider)); - $providerClient = $this->getMock('League\OAuth2\Client\Provider\ProviderInterface'); + $providerClient = $this->getMock('League\OAuth2\Client\Provider\IdentityProvider'); $providerClients->expects($this->once()) ->method('get') From 268512871026abc1215234a218d7117bf64b5f9b Mon Sep 17 00:00:00 2001 From: Ujjwal Ojha Date: Fri, 22 Aug 2014 21:47:58 +0545 Subject: [PATCH 06/12] Added "How It Works" --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index 73fbf7d..f7649e2 100644 --- a/README.md +++ b/README.md @@ -81,3 +81,14 @@ return [ ] ]; ``` + +## How It Works +### Login with OAuth 2.0 +1. **Client:** Client sends a `POST` request to the server at */oauth/token* with oauth2 authorization code. +2. **Server:** Then *authorization code* is exchanged for *provider access token*. +3. **Server:** User information is retrived using the *provider access token* from **Step 2**. +4. **Server:** Look up the user by the unique *provider id*. If user already exists, grab +the existing user, otherwise create a new user account. +5. **Server:** Reply with a *new access token*. + + From 06ae9d15d28f0aac1836d0b684bdc7573f0972bc Mon Sep 17 00:00:00 2001 From: Ujjwal Ojha Date: Sat, 23 Aug 2014 19:08:20 +0545 Subject: [PATCH 07/12] Fixed typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f7649e2..5d33dfd 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ The module provides a grant for a oauth2 server and it is also a client for oaut ## Configuring the module #### Setting the User class -User class implements the ZfrOAuth2\Server\Entity\TokenOwnerInterface interface `Hrevert\OauthClient\Model\UserInterface`. Then, you need to modify the Doctrine mapping to associate this interface with your own user class. +User class must implement `Hrevert\OauthClient\Model\UserInterface`. Then, you need to modify the Doctrine mapping to associate this interface with your own user class. ```php return [ From 31e07f63b4462a5504ebab714815920c57c2ace8 Mon Sep 17 00:00:00 2001 From: Ujjwal Ojha Date: Mon, 25 Aug 2014 20:11:05 +0545 Subject: [PATCH 08/12] Compatibility with oauth1 for future oauth1 support --- README.md | 2 +- src/Grant/Oauth2Client.php | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 73fbf7d..25521c6 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,7 @@ To automatically create a new user, you need to specify a callable for creating return [ 'ht_oauth_service_client' => [ - 'create_user_callable' => function(\League\OAuth2\Client\Provider\User $userDetails) { + 'create_user_callable' => function(\HtLeagueOauthClientModule\Model\UserInterface $userDetails) { $user = ......; $userProvider = new \Hrevert\OauthClient\Entity\UserProvider(); diff --git a/src/Grant/Oauth2Client.php b/src/Grant/Oauth2Client.php index 6f12abc..769f614 100644 --- a/src/Grant/Oauth2Client.php +++ b/src/Grant/Oauth2Client.php @@ -20,6 +20,7 @@ use ZfrOAuth2\Server\Grant\AuthorizationServerAwareTrait; use Hrevert\OauthClient\Entity\UserProvider; use Hrevert\OauthClient\Model\UserInterface; +use HtLeagueOauthClientModule\Model\Oauth2User; class Oauth2Client extends AbstractGrant implements AuthorizationServerAwareInterface { @@ -129,7 +130,7 @@ public function createTokenResponse(HttpRequest $request, Client $client = null, // by default, we expect the callable to return instance of "Hrevert\OauthClient\Model\UserProviderInterface" // because the developer may have extended the default implementation // Alternatively the callable may return user entity directly - $userProvider = $createUserCallable($userDetails); + $userProvider = $createUserCallable(new Oauth2User($userDetails)); if ($userProvider instanceof UserInterface) { $user = $userProvider; $userProvider = new UserProvider; From 8cfd8d64e5bfc2292a14a9ec72afbd078b6b5052 Mon Sep 17 00:00:00 2001 From: Ujjwal Ojha Date: Tue, 26 Aug 2014 11:58:31 +0545 Subject: [PATCH 09/12] Update dependency version --- composer.json | 2 +- tests/src/Grant/Oauth2ClientTest.php | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index b6d4574..36319b0 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ "require": { "php": ">=5.4", "hrevert/ht-oauth-client-module": "0.0.*", - "hrevert/ht-league-oauth-client-module": "0.0.*", + "hrevert/ht-league-oauth-client-module": "0.1.*", "zendframework/zend-stdlib": "~2.2", "zfr/zfr-oauth2-server-module": "0.5.*" }, diff --git a/tests/src/Grant/Oauth2ClientTest.php b/tests/src/Grant/Oauth2ClientTest.php index 2e5e2b6..17f1929 100644 --- a/tests/src/Grant/Oauth2ClientTest.php +++ b/tests/src/Grant/Oauth2ClientTest.php @@ -232,7 +232,8 @@ public function testCanCreateTokenResponse($hasRefreshGrant, UserProviderInterfa if (!$userProvider) { $userProvider = $this->getMock('Hrevert\OauthClient\Model\UserProviderInterface'); - $createUserCallable = function() use ($userProvider) { + $createUserCallable = function($oauth2User) use ($userProvider) { + $this->assertInstanceOf('HtLeagueOauthClientModule\Model\Oauth2User', $oauth2User); return $userProvider; }; $options->expects($this->once()) From 815e24e60b8ead9a061307dc84b9daa12bdccd1c Mon Sep 17 00:00:00 2001 From: Ujjwal Ojha Date: Tue, 26 Aug 2014 12:08:38 +0545 Subject: [PATCH 10/12] Possible tests fix 5.5 --- tests/src/Grant/Oauth2ClientTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/src/Grant/Oauth2ClientTest.php b/tests/src/Grant/Oauth2ClientTest.php index 17f1929..f839e23 100644 --- a/tests/src/Grant/Oauth2ClientTest.php +++ b/tests/src/Grant/Oauth2ClientTest.php @@ -295,7 +295,7 @@ private function getValidRefreshToken() $refreshToken->setToken('azerty_refresh'); $refreshToken->setScopes('read'); $validDate = new DateTime(); - $validDate->add(new DateInterval('P1D')); + $validDate->add(DateInterval::createFromDateString('3600 seconds')); $refreshToken->setExpiresAt($validDate); From 7a2b2833a455fcfa207bed46fb9119e25a26429e Mon Sep 17 00:00:00 2001 From: Ujjwal Ojha Date: Tue, 26 Aug 2014 12:16:50 +0545 Subject: [PATCH 11/12] Update HtLeagueOauthClientModule link --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f040cbe..a69829c 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ return [ ``` #### Provider configuration -You need to define the credentials like client id, client secret and other configuration. Read [this](https://github.com/hrevert/HtLeagueOauthClientModule/tree/0.0.1) for these configuration. +You need to define the credentials like client id, client secret and other configuration. Read [this](https://github.com/hrevert/HtLeagueOauthClientModule/tree/0.1.0) for these configuration. #### Adding grant types ```php From 187be646c371493d5102662545babab9b39749bf Mon Sep 17 00:00:00 2001 From: Ujjwal Ojha Date: Tue, 26 Aug 2014 16:06:22 +0545 Subject: [PATCH 12/12] version in installation --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a69829c..0a1430b 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ A Zend Framework 2 module which provides custom grant for [zfr-oauth2-server](ht The module provides a grant for a oauth2 server and it is also a client for oauth2 servers of facebook, google etc. So, it is named as server as well as client. ## Installation -* Add `"hrevert/ht-oauth-server-client-module": "dev-master"` to composer.json and run `php composer.phar update`. +* Add `"hrevert/ht-oauth-server-client-module": "0.1.*"` to composer.json and run `php composer.phar update`. * Enabled the following modules in `config/application.config.php`. ```php 'modules' => array(