forked from hwi/HWIOAuthBundle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
154 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the HWIOAuthBundle package. | ||
* | ||
* (c) Hardware.Info <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace HWI\Bundle\OAuthBundle\OAuth\ResourceOwner; | ||
|
||
use HWI\Bundle\OAuthBundle\Security\Core\Authentication\Token\OAuthToken; | ||
|
||
/** | ||
* MailRuResourceOwner | ||
* | ||
* @author Gaponov Igor <[email protected]> | ||
*/ | ||
class MailRuResourceOwner extends GenericOAuth2ResourceOwner | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
protected $options = array( | ||
'authorization_url' => 'https://connect.mail.ru/oauth/authorize', | ||
'access_token_url' => 'https://connect.mail.ru/oauth/token', | ||
'infos_url' => 'http://www.appsmail.ru/platform/api', | ||
); | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
protected $paths = array( | ||
'identifier' => 'uid', | ||
'nickname' => 'nick', | ||
'realname' => 'nick', | ||
'email' => 'email', | ||
); | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function getUserInformation(array $accessToken, array $extraParameters = array()) | ||
{ | ||
$params = array( | ||
'app_id' => $this->getOption('client_id'), | ||
'method' => 'users.getInfo', | ||
'secure' => '1', | ||
'session_key' => $accessToken['access_token'], | ||
); | ||
|
||
$sig = vprintf('app_id=%smethod=%ssecure=%ssession_key=%s', $params); | ||
|
||
$params['sig'] = md5($sig . $this->getOption('client_secret')); | ||
|
||
$url = $this->normalizeUrl($this->getOption('infos_url'), $params); | ||
|
||
$content = $this->doGetUserInformationRequest($url)->getContent(); | ||
$content = json_decode($content); | ||
if (isset($content[0])) { | ||
$content = (array) $content[0]; | ||
} | ||
|
||
$response = $this->getUserResponse(); | ||
$response->setResponse($content); | ||
$response->setResourceOwner($this); | ||
$response->setOAuthToken(new OAuthToken($accessToken)); | ||
|
||
return $response; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
Step 2x: Setup mail.ru | ||
============================ | ||
First you will have to register your application on Mail.ru. Check out the | ||
documentation for more information: http://api.mail.ru/docs/guides/oauth/sites/. | ||
|
||
Next configure a resource owner of type `mailru` with appropriate | ||
`client_id`, `client_secret` and `scope` (optional). | ||
|
||
```yaml | ||
# app/config/config.yml | ||
|
||
hwi_oauth: | ||
resource_owners: | ||
any_name: | ||
type: mailru | ||
client_id: <client_id> | ||
client_secret: <client_secret> | ||
``` | ||
Scopes are separate by semicolon, you can those scopes: `photos`, `guestbook`, `stream`, `messages`, `events`. | ||
|
||
When you're done. Continue by configuring the security layer or go back to | ||
setup more resource owners. | ||
|
||
- [Step 2: Configuring resource owners (Facebook, GitHub, Google, Windows Live and others](../2-configuring_resource_owners.md) | ||
- [Step 3: Configuring the security layer](../3-configuring_the_security_layer.md). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the HWIOAuthBundle package. | ||
* | ||
* (c) Hardware.Info <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace HWI\Bundle\OAuthBundle\Tests\OAuth\ResourceOwner; | ||
|
||
use HWI\Bundle\OAuthBundle\OAuth\ResourceOwner\MailRuResourceOwner; | ||
|
||
class MailRuResourceOwnerTest extends GenericOAuth2ResourceOwnerTest | ||
{ | ||
protected $userResponse = <<<json | ||
[ | ||
{ | ||
"user_id": "1", | ||
"name": "bar", | ||
"email": "baz" | ||
} | ||
] | ||
json; | ||
|
||
protected $paths = array( | ||
'identifier' => 'user_id', | ||
'nickname' => 'name', | ||
'email' => 'email', | ||
); | ||
|
||
protected function setUpResourceOwner($name, $httpUtils, array $options) | ||
{ | ||
$options = array_merge( | ||
array( | ||
'authorization_url' => 'https://connect.mail.ru/oauth/authorize', | ||
'access_token_url' => 'https://connect.mail.ru/oauth/token', | ||
'infos_url' => 'http://www.appsmail.ru/platform/api?method=users.getInfo', | ||
), | ||
$options | ||
); | ||
|
||
return new MailRuResourceOwner($this->buzzClient, $httpUtils, $options, $name, $this->storage); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ | |
"instagram", | ||
"jira", | ||
"linkedin", | ||
"mail.ru", | ||
"odnoklassniki", | ||
"qq", | ||
"sensio connect", | ||
|