mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-04 15:32:35 +00:00
init
This commit is contained in:
78
app/Support/SocialiteProviders/DropboxProvider.php
Normal file
78
app/Support/SocialiteProviders/DropboxProvider.php
Normal file
@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace App\Support\SocialiteProviders;
|
||||
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use Illuminate\Support\Arr;
|
||||
use Laravel\Socialite\Two\AbstractProvider;
|
||||
use Laravel\Socialite\Two\ProviderInterface;
|
||||
use Laravel\Socialite\Two\User;
|
||||
|
||||
class DropboxProvider extends AbstractProvider implements ProviderInterface
|
||||
{
|
||||
/**
|
||||
* Unique Provider Identifier.
|
||||
*/
|
||||
public const IDENTIFIER = 'DROPBOX';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $scopeSeparator = ' ';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getAuthUrl($state): string
|
||||
{
|
||||
return $this->buildAuthUrlFromBase('https://www.dropbox.com/oauth2/authorize', $state);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getTokenUrl(): string
|
||||
{
|
||||
return 'https://api.dropboxapi.com/oauth2/token';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getTokenFields($code): array
|
||||
{
|
||||
return array_merge(parent::getTokenFields($code), [
|
||||
'grant_type' => 'authorization_code',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
protected function getUserByToken($token)
|
||||
{
|
||||
$response = $this->getHttpClient()->post('https://api.dropboxapi.com/2/users/get_current_account', [
|
||||
'headers' => [
|
||||
'Authorization' => 'Bearer '.$token,
|
||||
],
|
||||
]);
|
||||
|
||||
return json_decode($response->getBody(), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function mapUserToObject(array $user): User
|
||||
{
|
||||
return (new User)->setRaw($user)->map([
|
||||
'id' => $user['account_id'],
|
||||
'nickname' => null,
|
||||
'name' => $user['name']['display_name'],
|
||||
'email' => $user['email'],
|
||||
'avatar' => Arr::get($user, 'profile_photo_url'),
|
||||
]);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user