-
Notifications
You must be signed in to change notification settings - Fork 463
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ignacio José Canó Cabral
committed
Feb 17, 2024
1 parent
5b04054
commit 7e868e8
Showing
5 changed files
with
196 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ parameters: | |
src/CampaignMonitor: '[email protected]:SocialiteProviders/CampaignMonitor.git' | ||
src/Cheddar: '[email protected]:SocialiteProviders/Cheddar.git' | ||
src/ClaveUnica: '[email protected]:SocialiteProviders/ClaveUnica.git' | ||
src/Clerk: '[email protected]:SocialiteProviders/Clerk.git' | ||
src/Cognito: '[email protected]:SocialiteProviders/Cognito.git' | ||
src/Coinbase: '[email protected]:SocialiteProviders/Coinbase.git' | ||
src/ConstantContact: '[email protected]:SocialiteProviders/ConstantContact.git' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace SocialiteProviders\Clerk; | ||
|
||
use SocialiteProviders\Manager\SocialiteWasCalled; | ||
|
||
class ClerkExtendSocialite | ||
{ | ||
/** | ||
* Register the provider. | ||
* | ||
* @param \SocialiteProviders\Manager\SocialiteWasCalled $socialiteWasCalled | ||
*/ | ||
public function handle(SocialiteWasCalled $socialiteWasCalled) | ||
{ | ||
$socialiteWasCalled->extendSocialite('clerk', Provider::class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<?php | ||
|
||
namespace SocialiteProviders\Clerk; | ||
|
||
use SocialiteProviders\Manager\OAuth2\AbstractProvider; | ||
use SocialiteProviders\Manager\OAuth2\User; | ||
|
||
class Provider extends AbstractProvider | ||
{ | ||
/** | ||
* Unique Provider Identifier. | ||
*/ | ||
public const IDENTIFIER = 'CLERK'; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected $scopes = ['profile','email']; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected $scopeSeparator = ' '; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function getBaseUrl() | ||
{ | ||
return $this->getConfig('base_url'); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function additionalConfigKeys() | ||
{ | ||
return ['base_url']; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function getAuthUrl($state) | ||
{ | ||
return $this->buildAuthUrlFromBase("{$this->getBaseUrl()}/oauth/authorize", $state); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function getTokenUrl() | ||
{ | ||
return "{$this->getBaseUrl()}/oauth/token"; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function getUserByToken($token) | ||
{ | ||
$response = $this->getHttpClient()->get("{$this->getBaseUrl()}/oauth/userinfo", [ | ||
'headers' => [ | ||
'Authorization' => 'Bearer '.$token, | ||
], | ||
]); | ||
return json_decode($response->getBody(), true); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function mapUserToObject(array $user) | ||
{ | ||
return (new User())->setRaw($user)->map([ | ||
'id' => $user['user_id'], | ||
'nickname' => $user['username'], | ||
'name' => $user['name'], | ||
'email' => $user['email'], | ||
'avatar' => $user['picture'], | ||
]); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function getTokenFields($code) | ||
{ | ||
return array_merge(parent::getTokenFields($code), [ | ||
'grant_type' => 'authorization_code' | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# Clerk | ||
|
||
This is a provider for [Clerk](https://clerk.com/) | ||
|
||
```bash | ||
composer require socialiteproviders/clerk | ||
``` | ||
|
||
## 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 | ||
'clerk' => [ | ||
'client_id' => env('CLERK_CLIENT_ID'), | ||
'client_secret' => env('CLERK_CLIENT_SECRET'), | ||
'redirect' => env('CLERK_CALLBACK_URL'), | ||
'base_url' => env('CLERK_BASE_URL'), | ||
], | ||
``` | ||
|
||
### Add base URL to `.env` | ||
|
||
Clerk provides a customer URL for your different projects for this reason you need to provide a base_url | ||
|
||
```bash | ||
CLERK_BASE_URL=https://example.clerk.accounts.dev | ||
``` | ||
|
||
### 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\Clerk\ClerkExtendSocialite::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('clerk')->redirect(); | ||
``` | ||
|
||
@TODO | ||
|
||
### Returned User fields | ||
|
||
- `id` | ||
- `nickname` | ||
- `name` | ||
- `email` | ||
- `avatar` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"name": "socialiteproviders/clerk", | ||
"description": "Clerk OAuth2 Provider for Laravel Socialite", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Ignacio Cano", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"require": { | ||
"php": "^8.0", | ||
"ext-json": "*", | ||
"socialiteproviders/manager": "^4.0" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"SocialiteProviders\\Clerk\\": "" | ||
} | ||
} | ||
} |