mirror of
https://github.com/bitinflow/accounts.git
synced 2026-03-14 14:05:52 +00:00
Improve api operations
Change directory structure Add bitinflow-accounts socialite provider Improve docs generation
This commit is contained in:
89
src/GhostZero/BitinflowAccounts/Socialite/Provider.php
Normal file
89
src/GhostZero/BitinflowAccounts/Socialite/Provider.php
Normal file
@@ -0,0 +1,89 @@
|
||||
<?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',
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user