Skip to content

Commit

Permalink
Added support for Yahoo OAuth 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
lopsided authored and stloyd committed Jan 29, 2013
1 parent 27eaab1 commit 99ab794
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 1 deletion.
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
'oauth1',
'linkedin',
'twitter',
'yahoo',
);

/**
Expand Down
60 changes: 60 additions & 0 deletions OAuth/ResourceOwner/YahooResourceOwner.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?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;

/**
* YahooResourceOwner
*
* @author Tom <[email protected]>
* @author Alexander <[email protected]>
*/
class YahooResourceOwner extends GenericOAuth1ResourceOwner
{
/**
* {@inheritDoc}
*/
protected $options = array(
'authorization_url' => 'https://api.login.yahoo.com/oauth/v2/request_auth',
'request_token_url' => 'https://api.login.yahoo.com/oauth/v2/get_request_token',
'access_token_url' => 'https://api.login.yahoo.com/oauth/v2/get_token',
'infos_url' => 'http://social.yahooapis.com/v1/user/{guid}/profile',
'user_response_class' => '\HWI\Bundle\OAuthBundle\OAuth\Response\PathUserResponse',
'realm' => 'yahooapis.com',
);

/**
* {@inheritDoc}
*/
protected $paths = array(
'username' => 'profile.guid',
'displayname' => 'profile.nickname',
);

/**
* Override to replace {guid} in the infos_url with the authenticating user's yahoo id
* {@inheritDoc}
*/
public function getUserInformation($accessToken)
{
$this->options['infos_url'] = str_replace('{guid}', $accessToken['xoauth_yahoo_guid'], $this->getOption('infos_url'));
return parent::getUserInformation($accessToken);
}

/**
* Override to set the Accept header as otherwise Yahoo defaults to XML
* {@inheritDoc}
*/
protected function doGetUserInformationRequest($url, array $parameters = array())
{
return $this->httpRequest($url, null, $parameters, array('Accept: application/json'), 'GET');
}
}
3 changes: 3 additions & 0 deletions Resources/config/oauth.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<parameter key="hwi_oauth.resource_owner.twitter.class">HWI\Bundle\OAuthBundle\OAuth\ResourceOwner\TwitterResourceOwner</parameter>
<parameter key="hwi_oauth.resource_owner.vkontakte.class">HWI\Bundle\OAuthBundle\OAuth\ResourceOwner\VkontakteResourceOwner</parameter>
<parameter key="hwi_oauth.resource_owner.windows_live.class">HWI\Bundle\OAuthBundle\OAuth\ResourceOwner\WindowsLiveResourceOwner</parameter>
<parameter key="hwi_oauth.resource_owner.yahoo.class">HWI\Bundle\OAuthBundle\OAuth\ResourceOwner\YahooResourceOwner</parameter>

<parameter key="hwi_oauth.resource_ownermap.class">HWI\Bundle\OAuthBundle\Security\Http\ResourceOwnerMap</parameter>
<parameter key="hwi_oauth.security.oauth_utils.class">HWI\Bundle\OAuthBundle\Security\OAuthUtils</parameter>
Expand Down Expand Up @@ -118,5 +119,7 @@
parent="hwi_oauth.abstract_resource_owner.oauth1" abstract="true" />
<service id="hwi_oauth.abstract_resource_owner.twitter" class="%hwi_oauth.resource_owner.twitter.class%"
parent="hwi_oauth.abstract_resource_owner.oauth1" abstract="true" />
<service id="hwi_oauth.abstract_resource_owner.yahoo" class="%hwi_oauth.resource_owner.yahoo.class%"
parent="hwi_oauth.abstract_resource_owner.oauth1" abstract="true" />
</services>
</container>
28 changes: 28 additions & 0 deletions Resources/doc/2x-yahoo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Step 2x: Setup Yahoo
=======================
First you will have to register your application on Yahoo ("Create a Project"). Check out the
documentation for more information: http://developer.yahoo.com/oauth/.

The Yahoo Resource Owner uses the Yahoo Profile API to get user information, so when setting up your Yahoo Project
you must ensure that you have enabled access to the "Social Directory" service, with at least "Read Public" access
under the "Social Directory (Profiles)" section.

Next configure a resource owner of type `yahoo` with appropriate `client_id`,
`client_secret`.

``` yaml
# app/config.yml

hwi_oauth:
resource_owners:
any_name:
type: yahoo
client_id: <client_id>
client_secret: <client_secret>
```
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).
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "hwi/oauth-bundle",
"type": "symfony-bundle",
"description": "Support for authenticating users via oauth in Symfony2.",
"keywords": ["security", "firewall", "oauth", "facebook", "oauth2", "github", "google", "windows live", "vkontakte", "oauth1", "twitter", "linkedin", "sensio connect"],
"keywords": ["security", "firewall", "oauth", "facebook", "oauth2", "github", "google", "windows live", "vkontakte", "oauth1", "twitter", "linkedin", "sensio connect", "yahoo"],
"homepage": "http://github.com/hwi/HWIOAuthBundle",
"license": "MIT",

Expand Down

0 comments on commit 99ab794

Please sign in to comment.