Skip to content

Commit

Permalink
Rename file. (#827)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasmichot committed Apr 13, 2022
0 parents commit 9d57eb9
Show file tree
Hide file tree
Showing 4 changed files with 188 additions and 0 deletions.
18 changes: 18 additions & 0 deletions DropboxExtendSocialite.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace SocialiteProviders\Dropbox;

use SocialiteProviders\Manager\SocialiteWasCalled;

class DropboxExtendSocialite
{
/**
* Register the provider.
*
* @param \SocialiteProviders\Manager\SocialiteWasCalled $socialiteWasCalled
*/
public function handle(SocialiteWasCalled $socialiteWasCalled)
{
$socialiteWasCalled->extendSocialite('dropbox', Provider::class);
}
}
88 changes: 88 additions & 0 deletions Provider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?php

namespace SocialiteProviders\Dropbox;

use GuzzleHttp\RequestOptions;
use Illuminate\Support\Arr;
use SocialiteProviders\Manager\OAuth2\AbstractProvider;
use SocialiteProviders\Manager\OAuth2\User;

class Provider extends AbstractProvider
{
/**
* Unique Provider Identifier.
*/
public const IDENTIFIER = 'DROPBOX';

/**
* {@inheritdoc}
*/
protected $scopeSeparator = ' ';

/**
* {@inheritdoc}
*/
protected $scopes = [
'account_info.read',
];

/**
* {@inheritdoc}
*/
protected function getAuthUrl($state)
{
return $this->buildAuthUrlFromBase(
'https://www.dropbox.com/oauth2/authorize',
$state
);
}

/**
* {@inheritdoc}
*/
protected function getTokenUrl()
{
return 'https://api.dropboxapi.com/oauth2/token';
}

/**
* {@inheritdoc}
*/
protected function getUserByToken($token)
{
$response = $this->getHttpClient()->post(
'https://api.dropboxapi.com/2/users/get_current_account',
[
RequestOptions::HEADERS => [
'Authorization' => 'Bearer '.$token,
],
]
);

return json_decode((string) $response->getBody(), true);
}

/**
* {@inheritdoc}
*/
protected function mapUserToObject(array $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'),
]);
}

/**
* {@inheritdoc}
*/
protected function getTokenFields($code)
{
return array_merge(parent::getTokenFields($code), [
'grant_type' => 'authorization_code',
]);
}
}
49 changes: 49 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Dropbox

```bash
composer require socialiteproviders/dropbox
```

## Installation & Basic Usage

Please see the [Base Installation Guide](https://socialiteproviders.com/usage/), then follow the provider specific instructions below.

### Add configuration to `config/services.php`

```php
'dropbox' => [
'client_id' => env('DROPBOX_CLIENT_ID'),
'client_secret' => env('DROPBOX_CLIENT_SECRET'),
'redirect' => env('DROPBOX_REDIRECT_URI')
],
```

### Add provider event listener

Configure the package's listener to listen for `SocialiteWasCalled` events.

Add the event to your `listen[]` array in `app/Providers/EventServiceProvider`. See the [Base Installation Guide](https://socialiteproviders.com/usage/) for detailed instructions.

```php
protected $listen = [
\SocialiteProviders\Manager\SocialiteWasCalled::class => [
// ... other providers
\SocialiteProviders\Dropbox\DropboxExtendSocialite::class.'@handle',
],
];
```

### Usage

You should now be able to use the provider like you would regularly use Socialite (assuming you have the facade installed):

```php
return Socialite::driver('dropbox')->redirect();
```

### Returned User fields

- ``id``
- ``name``
- ``email``
- ``avatar``
33 changes: 33 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "socialiteproviders/dropbox",
"description": "Dropbox OAuth2 Provider for Laravel Socialite",
"keywords": [
"dropbox",
"laravel",
"oauth",
"provider",
"socialite"
],
"license": "MIT",
"authors": [
{
"name": "Brian Faust",
"email": "hello@brianfaust.de"
}
],
"require": {
"php": "^7.2 || ^8.0",
"ext-json": "*",
"socialiteproviders/manager": "~4.0"
},
"autoload": {
"psr-4": {
"SocialiteProviders\\Dropbox\\": ""
}
},
"support": {
"issues": "https://github.com/socialiteproviders/providers/issues",
"source": "https://github.com/socialiteproviders/providers",
"docs": "https://socialiteproviders.com/dropbox"
}
}

0 comments on commit 9d57eb9

Please sign in to comment.