Skip to content

Instantly share code, notes, and snippets.

@scottybo
Created June 4, 2018 17:55
Show Gist options
  • Save scottybo/7b0e9bf6d527ecfef56d44b9f023e90e to your computer and use it in GitHub Desktop.
Save scottybo/7b0e9bf6d527ecfef56d44b9f023e90e to your computer and use it in GitHub Desktop.
Socialite Wordpress Self Hosted
<?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