Created
June 4, 2018 17:55
-
-
Save scottybo/7b0e9bf6d527ecfef56d44b9f023e90e to your computer and use it in GitHub Desktop.
Socialite Wordpress Self Hosted
This file contains hidden or 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
<?php | |
namespace SocialiteProviders\WordPress; | |
use SocialiteProviders\Manager\OAuth2\User; | |
use Laravel\Socialite\Two\ProviderInterface; | |
use SocialiteProviders\Manager\OAuth2\AbstractProvider; | |
class Provider extends AbstractProvider implements ProviderInterface | |
{ | |
/** | |
* Unique Provider Identifier. | |
*/ | |
const IDENTIFIER = 'WORDPRESS'; | |
/** | |
* The scopes being requested. | |
* | |
* @var array | |
*/ | |
protected $scopes = []; | |
/** | |
* {@inheritdoc} | |
*/ | |
protected function getAuthUrl($state) | |
{ | |
return $this->buildAuthUrlFromBase('https://www.thirty.site/oauth/authorize', $state); | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
protected function getTokenUrl() | |
{ | |
return 'https://www.thirty.site/oauth/token'; | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
protected function getUserByToken($token) | |
{ | |
$response = $this->getHttpClient()->get( | |
'https://www.thirty.site/oauth/me', [ | |
'headers' => [ | |
'Authorization' => 'Bearer '.$token, | |
], | |
]); | |
return json_decode($response->getBody()->getContents(), true); | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
protected function mapUserToObject(array $user) | |
{ | |
return (new User())->setRaw($user)->map( | |
[ | |
'id' => $user['user_id'], | |
'nickname' => $user['user_nicename'], | |
'name' => $user['display_name'], | |
'email' => $user['email'], | |
'avatar' => null, | |
] | |
); | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
protected function getTokenFields($code) | |
{ | |
return array_merge(parent::getTokenFields($code), [ | |
'grant_type' => 'authorization_code', | |
]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment