Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mosaxiv committed Mar 24, 2018
0 parents commit 4a949cf
Show file tree
Hide file tree
Showing 6 changed files with 162 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 4
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false

[*.yml]
indent_style = space
indent_size = 2
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.idea
vendor/
composer.lock
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2018 Socialite

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Yahoo Provider

## Installation

```
composer require socialite-manager/yahoo-provider
```

## Usage

```php
use Socialite\Provider\YahooProvider;
use Socialite\Socialite;

Socialite::driver(YahooProvider::class, $config);
```
26 changes: 26 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "socialite-manager/yahoo-provider",
"description": "Yahoo provider",
"license": "MIT",
"require": {
"socialite-manager/socialite": "^1.0"
},
"require-dev": {
"phpstan/phpstan": "^0.9.2",
"squizlabs/php_codesniffer": "^3.0"
},
"autoload": {
"psr-4": {
"Socialite\\Provider\\": "src/"
}
},
"scripts": {
"check": [
"@cs-check",
"@analyse"
],
"cs-check": "phpcs --standard=PSR2 --colors -p ./src",
"cs-fix": "phpcbf --standard=PSR2 --colors ./src",
"analyse": "phpstan analyse -l max src"
}
}
80 changes: 80 additions & 0 deletions src/YahooProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php

namespace Socialite\Provider;

use Socialite\Two\AbstractProvider;
use Socialite\Two\User;
use Socialite\Util\A;

class YahooProvider extends AbstractProvider
{
/**
* @var string
*/
protected $xoauth_yahoo_guid;

/**
* {@inheritdoc}
*/
protected function getAuthUrl(string $state)
{
return $this->buildAuthUrlFromBase('https://api.login.yahoo.com/oauth2/request_auth', $state);
}

/**
* {@inheritdoc}
*/
protected function getTokenUrl()
{
return 'https://api.login.yahoo.com/oauth2/get_token';
}

/**
* {@inheritdoc}
*/
protected function getUserByToken(string $token)
{
$response = $this->getHttpClient()->get('https://social.yahooapis.com/v1/user/' . $this->xoauth_yahoo_guid . '/profile?format=json', [
'headers' => [
'Authorization' => 'Bearer ' . $token,
],
]);
return json_decode($response->getBody(), true)['profile'];
}

/**
* Note: To have access to e-mail, you need to request "Profiles (Social Directory) - Read/Write Public and Private"
* {@inheritdoc}
*/
protected function mapUserToObject(array $user)
{
return (new User())->setRaw($user)->map([
'id' => $user['guid'],
'nickname' => $user['nickname'],
'name' => trim(sprintf('%s %s', A::get($user, 'givenName'), A::get($user, 'familyName'))),
'email' => A::get($user, 'emails.0.handle'),
'avatar' => A::get($user, 'image.imageUrl'),
]);
}

/**
* {@inheritdoc}
*/
protected function getTokenFields(string $code)
{
return array_merge(parent::getTokenFields($code), [
'grant_type' => 'authorization_code',
]);
}

/**
* {@inheritdoc}
*/
public function getAccessTokenResponse(string $code)
{
$response = parent::getAccessTokenResponse($code);
$this->xoauth_yahoo_guid = A::get($response, 'xoauth_yahoo_guid');

return $response;
}
}

0 comments on commit 4a949cf

Please sign in to comment.