Created
May 27, 2019 09:57
-
-
Save Cannonb4ll/bdcaa86612b6a83313a9a087fdc37d25 to your computer and use it in GitHub Desktop.
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
// Inside appserviceprovider: | |
private function bootPloiSocialite() | |
{ | |
$socialite = $this->app->make('Laravel\Socialite\Contracts\Factory'); | |
$socialite->extend( | |
'ploi', | |
function ($app) use ($socialite) { | |
$config = $app['config']['services.ploi']; | |
return $socialite->buildProvider(PloiProvider::class, $config); | |
} | |
); | |
} |
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 App\SocialProviders; | |
use Laravel\Socialite\Two\AbstractProvider; | |
use Laravel\Socialite\Two\ProviderInterface; | |
use Laravel\Socialite\Two\User; | |
class PloiProvider extends AbstractProvider implements ProviderInterface | |
{ | |
protected $baseUrl = 'http://b9bee745.ngrok.io'; | |
/** | |
* {@inheritdoc} | |
*/ | |
protected function getAuthUrl($state) | |
{ | |
return $this->buildAuthUrlFromBase($this->baseUrl . '/oauth/authorize', $state); | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
protected function getTokenUrl() | |
{ | |
return $this->baseUrl . '/oauth/token'; | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
protected function getTokenFields($code) | |
{ | |
return array_add( | |
parent::getTokenFields($code), 'grant_type', 'authorization_code' | |
); | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
protected function getUserByToken($token) | |
{ | |
$response = $this->getHttpClient()->get($this->baseUrl . '/api/user', [ | |
'headers' => [ | |
'Authorization' => 'Bearer ' . $token, | |
], | |
]); | |
return json_decode($response->getBody(), true); | |
} | |
/** | |
* Format the given scopes. | |
* | |
* @param array $scopes | |
* @param string $scopeSeparator | |
* | |
* @return string | |
*/ | |
protected function formatScopes(array $scopes, $scopeSeparator) | |
{ | |
return implode($scopeSeparator, $scopes); | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
protected function mapUserToObject(array $user) | |
{ | |
$user = array_get($user, 'data'); | |
return (new User)->setRaw($user)->map([ | |
'id' => $user['email'], | |
'name' => $user['name'], | |
'email' => $user['email'], | |
'avatar' => $user['avatar'], | |
'country' => $user['country'], | |
'timezone' => $user['timezone'], | |
'plan_expires_at' => $user['plan_expires_at'] | |
]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment