mirror of
https://github.com/bitinflow/accounts.git
synced 2026-03-13 13:35:52 +00:00
Change directory structure Add bitinflow-accounts socialite provider Improve docs generation
89 lines
2.0 KiB
PHP
89 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace GhostZero\BitinflowAccounts\Socialite;
|
|
|
|
use GhostZero\BitinflowAccounts\Enums\Scope;
|
|
use Illuminate\Support\Arr;
|
|
use Laravel\Socialite\Two\ProviderInterface;
|
|
use SocialiteProviders\Manager\OAuth2\AbstractProvider;
|
|
use SocialiteProviders\Manager\OAuth2\User;
|
|
|
|
/**
|
|
* @author René Preuß <rene@preuss.io>
|
|
*/
|
|
class Provider extends AbstractProvider implements ProviderInterface
|
|
{
|
|
|
|
/**
|
|
* Unique Provider Identifier.
|
|
*/
|
|
const IDENTIFIER = 'BITINFLOW_ACCOUNTS';
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
protected $scopes = [Scope::READ_USER];
|
|
|
|
/**
|
|
* {@inherticdoc}.
|
|
*/
|
|
protected $scopeSeparator = ' ';
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
protected function getAuthUrl($state)
|
|
{
|
|
return $this->buildAuthUrlFromBase(
|
|
'https://accounts.bitinflow.com/oauth/authorize', $state
|
|
);
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
protected function getTokenUrl()
|
|
{
|
|
return 'https://accounts.bitinflow.com/oauth/token';
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
protected function getUserByToken($token)
|
|
{
|
|
$response = $this->getHttpClient()->get(
|
|
'https://accounts.bitinflow.com/api/user', [
|
|
'headers' => [
|
|
'Accept' => 'application/json',
|
|
'Authorization' => 'Bearer ' . $token,
|
|
],
|
|
]);
|
|
|
|
return json_decode($response->getBody()->getContents(), true);
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
protected function mapUserToObject(array $user)
|
|
{
|
|
return (new User())->setRaw($user)->map([
|
|
'id' => $user['id'],
|
|
'nickname' => $user['name'],
|
|
'name' => $user['name'],
|
|
'email' => Arr::get($user, 'email'),
|
|
'avatar' => $user['avatar'],
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
protected function getTokenFields($code)
|
|
{
|
|
return array_merge(parent::getTokenFields($code), [
|
|
'grant_type' => 'authorization_code',
|
|
]);
|
|
}
|
|
} |