Skip to content

Commit

Permalink
Added Mail.ru
Browse files Browse the repository at this point in the history
  • Loading branch information
igaponov committed Sep 11, 2013
1 parent 156372a commit 6a498f4
Show file tree
Hide file tree
Showing 9 changed files with 154 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Changelog
* Added Box resource owner
* Added Dailymotion resource owner
* Added DeviantArt resource owner
* Added Mail.ru resource owner
* Added Sina Weibo resource owner
* Added QQ.com resource owner
* Added Wordpress resource owner
Expand Down
1 change: 1 addition & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class Configuration implements ConfigurationInterface
'google',
'instagram',
'linkedin',
'mailru',
'odnoklassniki',
'qq',
'sensio_connect',
Expand Down
73 changes: 73 additions & 0 deletions OAuth/ResourceOwner/MailRuResourceOwner.php
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;
}
}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ This bundle contains support for 20+ different providers:
* Instagram,
* JIRA,
* LinkedIn,
* Mail.ru
* Odnoklassniki,
* QQ,
* Sensio Connect,
Expand Down
3 changes: 3 additions & 0 deletions Resources/config/oauth.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
<parameter key="hwi_oauth.resource_owner.instagram.class">HWI\Bundle\OAuthBundle\OAuth\ResourceOwner\InstagramResourceOwner</parameter>
<parameter key="hwi_oauth.resource_owner.jira.class">HWI\Bundle\OAuthBundle\OAuth\ResourceOwner\JiraResourceOwner</parameter>
<parameter key="hwi_oauth.resource_owner.linkedin.class">HWI\Bundle\OAuthBundle\OAuth\ResourceOwner\LinkedinResourceOwner</parameter>
<parameter key="hwi_oauth.resource_owner.mailru.class">HWI\Bundle\OAuthBundle\OAuth\ResourceOwner\MailRuResourceOwner</parameter>
<parameter key="hwi_oauth.resource_owner.qq.class">HWI\Bundle\OAuthBundle\OAuth\ResourceOwner\QQResourceOwner</parameter>
<parameter key="hwi_oauth.resource_owner.sensio_connect.class">HWI\Bundle\OAuthBundle\OAuth\ResourceOwner\SensioConnectResourceOwner</parameter>
<parameter key="hwi_oauth.resource_owner.sina_weibo.class">HWI\Bundle\OAuthBundle\OAuth\ResourceOwner\SinaWeiboResourceOwner</parameter>
Expand Down Expand Up @@ -137,6 +138,8 @@
parent="hwi_oauth.abstract_resource_owner.oauth2" abstract="true" />
<service id="hwi_oauth.abstract_resource_owner.linkedin" class="%hwi_oauth.resource_owner.linkedin.class%"
parent="hwi_oauth.abstract_resource_owner.oauth2" abstract="true" />
<service id="hwi_oauth.abstract_resource_owner.mailru" class="%hwi_oauth.resource_owner.mailru.class%"
parent="hwi_oauth.abstract_resource_owner.oauth2" abstract="true" />
<service id="hwi_oauth.abstract_resource_owner.qq" class="%hwi_oauth.resource_owner.qq.class%"
parent="hwi_oauth.abstract_resource_owner.oauth2" abstract="true" />
<service id="hwi_oauth.abstract_resource_owner.sensio_connect" class="%hwi_oauth.resource_owner.sensio_connect.class%"
Expand Down
1 change: 1 addition & 0 deletions Resources/doc/2-configuring_resource_owners.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ hwi_oauth:
- [Instagram](resource_owners/instagram.md)
- [Jira](resource_owners/jira.md)
- [Linkedin](resource_owners/linkedin.md)
- [Mail.ru](resource_owners/mailru.md)
- [Odnoklassniki](resource_owners/odnoklassniki.md)
- [QQ](resource_owners/qq.md)
- [SensioLabs Connect](resource_owners/sensio_connect.md)
Expand Down
26 changes: 26 additions & 0 deletions Resources/doc/resource_owners/mailru.md
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).
47 changes: 47 additions & 0 deletions Tests/OAuth/ResourceOwner/MailRuResourceOwnerTest.php
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);
}
}
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"instagram",
"jira",
"linkedin",
"mail.ru",
"odnoklassniki",
"qq",
"sensio connect",
Expand Down

0 comments on commit 6a498f4

Please sign in to comment.