diff --git a/src/GoHighLevel/GoHighLevelExtendSocialite.php b/src/GoHighLevel/GoHighLevelExtendSocialite.php new file mode 100644 index 000000000..d54aaa60b --- /dev/null +++ b/src/GoHighLevel/GoHighLevelExtendSocialite.php @@ -0,0 +1,13 @@ +extendSocialite('gohighlevel', Provider::class); + } +} diff --git a/src/GoHighLevel/Provider.php b/src/GoHighLevel/Provider.php new file mode 100644 index 000000000..6db1e7984 --- /dev/null +++ b/src/GoHighLevel/Provider.php @@ -0,0 +1,83 @@ +buildAuthUrlFromBase('https://marketplace.leadconnectorhq.com/oauth/chooselocation', $state); + } + + protected function getTokenUrl(): string + { + return 'https://services.leadconnectorhq.com/oauth/token'; + } + + /** + * {@inheritdoc} + */ + protected function getUserByToken($token) + { + $userId = $this->credentialsResponseBody['userId'] ?? null; + + if (!$userId) { + return null; + } + + $response = $this->getHttpClient()->get('https://services.leadconnectorhq.com/users/' . $userId); + + return json_decode((string) $response->getBody(), true); + } + + /** + * {@inheritdoc} + */ + protected function mapUserToObject(array $user) + { + return (new User)->setRaw($user)->map([ + 'name' => Arr::get($user, 'name'), + 'email' => Arr::get($user, 'email'), + 'id' => Arr::get($user, 'id'), + 'nickname' => null, + 'avatar' => null, + ]); + } + + /** + * Acquire a new access token using the refresh token. + * + * @see https://highlevel.stoplight.io/docs/integrations/00d0c0ecaa369-get-access-token + * + * @param string $refreshToken + * + * @return array + */ + public function refreshToken($refreshToken) + { + $response = $this->getHttpClient()->post($this->getTokenUrl(), [ + RequestOptions::HEADERS => [ + 'Accept' => 'application/json', + ], + RequestOptions::FORM_PARAMS => [ + 'client_id' => $this->clientId, + 'client_secret' => $this->clientSecret, + 'grant_type' => 'refresh_token', + 'refresh_token' => $refreshToken, + ], + ]); + + return json_decode((string) $response->getBody(), true); + } +} diff --git a/src/GoHighLevel/README.md b/src/GoHighLevel/README.md new file mode 100644 index 000000000..d1bca00d0 --- /dev/null +++ b/src/GoHighLevel/README.md @@ -0,0 +1,64 @@ +# GoHighLevel + +```bash +composer require socialiteproviders/gohighlevel +``` + +## 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 +'gohighlevel' => [ + 'client_id' => env('GOHIGHLEVEL_CLIENT_ID'), + 'client_secret' => env('GOHIGHLEVEL_CLIENT_SECRET'), + 'redirect' => env('GOHIGHLEVEL_REDIRECT_URI') +], +``` + +### Add provider event listener + +#### Laravel 11+ + +In Laravel 11, the default `EventServiceProvider` provider was removed. Instead, add the listener using the `listen` method on the `Event` facade, in your `AppServiceProvider` `boot` method. + +* Note: You do not need to add anything for the built-in socialite providers unless you override them with your own providers. + +```php +Event::listen(function (\SocialiteProviders\Manager\SocialiteWasCalled $event) { + $event->extendSocialite('gohighlevel', \SocialiteProviders\GoHighLevel\Provider::class); +}); +``` +
+ +Laravel 10 or below + +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\GoHighLevel\GoHighLevelExtendSocialite::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('gohighlevel')->redirect(); +``` + +### Returned User fields + +- ``id`` +- ``name`` +- ``email`` diff --git a/src/GoHighLevel/composer.json b/src/GoHighLevel/composer.json new file mode 100644 index 000000000..dfc9ffb57 --- /dev/null +++ b/src/GoHighLevel/composer.json @@ -0,0 +1,33 @@ +{ + "name": "socialiteproviders/gohighlevel", + "description": "GoHighLevel OAuth2 Provider for Laravel Socialite", + "license": "MIT", + "keywords": [ + "gohighlevel", + "laravel", + "oauth", + "provider", + "socialite" + ], + "authors": [ + { + "name": "atymic", + "email": "hello@atymic.dev" + } + ], + "support": { + "issues": "https://github.com/socialiteproviders/providers/issues", + "source": "https://github.com/socialiteproviders/providers", + "docs": "https://socialiteproviders.com/gohighlevel" + }, + "require": { + "php": "^8.1", + "ext-json": "*", + "socialiteproviders/manager": "^4.8" + }, + "autoload": { + "psr-4": { + "SocialiteProviders\\GoHighLevel\\": "" + } + } +}