-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Autodesk Platform Services (Forge) OAuth provider (#1008)
Co-authored-by: atymic <[email protected]>
- Loading branch information
Showing
4 changed files
with
202 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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace SocialiteProviders\AutodeskAPS; | ||
|
||
use SocialiteProviders\Manager\SocialiteWasCalled; | ||
|
||
class AutodeskAPSExtendSocialite | ||
{ | ||
/** | ||
* Register the provider. | ||
* | ||
* @param SocialiteWasCalled $socialiteWasCalled | ||
*/ | ||
public function handle(SocialiteWasCalled $socialiteWasCalled): void | ||
{ | ||
$socialiteWasCalled->extendSocialite('aps', 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,92 @@ | ||
<?php | ||
|
||
namespace SocialiteProviders\AutodeskAPS; | ||
|
||
use GuzzleHttp\RequestOptions; | ||
use SocialiteProviders\Manager\OAuth2\AbstractProvider; | ||
use SocialiteProviders\Manager\OAuth2\User; | ||
|
||
class Provider extends AbstractProvider | ||
{ | ||
public const IDENTIFIER = 'AUTODESKAPS'; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected $scopes = []; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected $scopeSeparator = ' '; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function getAuthUrl($state): string | ||
{ | ||
return | ||
$this->buildAuthUrlFromBase( | ||
'https://developer.api.autodesk.com/authentication/v1/authorize', | ||
$state | ||
); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function getTokenUrl(): string | ||
{ | ||
return 'https://developer.api.autodesk.com/authentication/v1/gettoken'; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function getTokenFields($code): array | ||
{ | ||
return parent::getTokenFields($code); | ||
} | ||
|
||
/** | ||
* @param string $token | ||
* | ||
* @throws \GuzzleHttp\Exception\GuzzleException | ||
* | ||
* @return array | ||
*/ | ||
protected function getUserByToken($token): array | ||
{ | ||
$response = $this->getHttpClient()->get( | ||
'https://developer.api.autodesk.com/userprofile/v1/users/@me', | ||
[ | ||
RequestOptions::HEADERS => [ | ||
'Accept' => 'application/json', | ||
'Authorization' => 'Bearer '.$token, | ||
], | ||
] | ||
); | ||
|
||
return (array) json_decode((string) $response->getBody(), true); | ||
} | ||
|
||
/** | ||
* https://forge.autodesk.com/en/docs/oauth/v2/reference/http/users-@me-GET/. | ||
* | ||
* {@inheritdoc} | ||
*/ | ||
protected function mapUserToObject(array $user): \SocialiteProviders\Manager\OAuth2\User | ||
{ | ||
return (new User())->setRaw($user)->map([ | ||
'id' => $user['userId'], | ||
'email' => $user['emailId'], | ||
'username' => $user['userName'], | ||
'first_name' => $user['firstName'], | ||
'last_name' => $user['lastName'], | ||
'country_code' => $user['countryCode'], | ||
'language' => $user['language'], | ||
'profile_images' => $user['profileImages'], | ||
'website' => $user['websiteUrl'] ?? null, | ||
]); | ||
} | ||
} |
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,56 @@ | ||
# APS | ||
|
||
This is a socialite provider for Autodesk APS (formerly Forge). | ||
|
||
```bash | ||
composer require socialiteproviders/autodesk-aps | ||
``` | ||
|
||
## 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 | ||
// Autodesk APS (Forge) | ||
'autodesk_aps' => [ | ||
'client_id' => env('AUTODESK_APS_CLIENT_ID'), | ||
'client_secret' => env('AUTODESK_APS_CLIENT_SECRET'), | ||
'redirect' => env('AUTODESK_APS_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\APS\AutodeskAPSExtendSocialite::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('autodeskaps')->redirect(); | ||
``` | ||
|
||
### Returned user fields | ||
|
||
- `id` | ||
- `name` | ||
- `email` | ||
- `username` | ||
|
||
### Reference | ||
|
||
- [Autodesk documentation](https://aps.autodesk.com/en/docs/oauth/v1/tutorials/get-3-legged-token/); |
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,36 @@ | ||
{ | ||
"name": "socialiteproviders/aps", | ||
"description": "Autodesk Platform Services (Forge) OAuth2 Provider for Laravel Socialite", | ||
"license": "MIT", | ||
"keywords": [ | ||
"laravel", | ||
"oauth", | ||
"provider", | ||
"socialite", | ||
"autodesk", | ||
"forge", | ||
"aps", | ||
"autodesk platform services" | ||
], | ||
"authors": [ | ||
{ | ||
"name": "Derkjan Super", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"support": { | ||
"issues": "https://github.com/socialiteproviders/providers/issues", | ||
"source": "https://github.com/socialiteproviders/providers", | ||
"docs": "https://socialiteproviders.com/aps" | ||
}, | ||
"require": { | ||
"php": "^8.0", | ||
"ext-json": "*", | ||
"socialiteproviders/manager": "^4.0" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"SocialiteProviders\\APS\\": "" | ||
} | ||
} | ||
} |