Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pumukit/pumukitoauth2bundle
https://github.com/pumukit/pumukitoauth2bundle
Last synced: 1 day ago
JSON representation
- Host: GitHub
- URL: https://github.com/pumukit/pumukitoauth2bundle
- Owner: pumukit
- Created: 2020-11-23T13:47:13.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2021-10-08T07:14:18.000Z (about 3 years ago)
- Last Synced: 2024-04-18T18:28:18.327Z (8 months ago)
- Language: PHP
- Size: 10.7 KB
- Stars: 0
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# OAuth 2.0 Client
This package provides OAuth 2.0 support for the PHP League's [OAuth 2.0 Client](https://github.com/thephpleague/oauth2-client).
## Installation
To install, use composer:
```
composer require teltek/pumukit-oauth2-bundle
```if not, add this to config/bundles.php
```
Pumukit\OAuth2Bundle\PumukitOAuth2Bundle::class => ['all' => true]
```Then execute the following commands
```bash
php bin/console cache:clear
php bin/console cache:clear --env=prod
php bin/console assets:install
```## Usage
Usage is the same as The League's OAuth client, using `Pumukit\OAuth2Bundle\Provider\Oam` as the provider.
### Authorization Code Flow
```php
$provider = new Pumukit\OAuth2Bundle\Provider\Oam(
'clientId' => 'your client id',
'clientSecret' => 'your client secret',
'redirectUri' => 'your redirect uri',
'urlAuthorize' => 'your url authorize',
'urlAccessToken' => 'your url access token',
'urlResourceOwnerDetails' => 'your url resource owner details',
]);if (!isset($_GET['code'])) {
$options['scope'] = array('Customer.Info','UserProfile.me');
$authorizationUrl = $provider->getAuthorizationUrl($options);$_SESSION['oauth2state'] = $provider->getState();
header('Location: '.$authorizationUrl);
exit;} elseif (empty($_GET['state']) || ($_GET['state'] !== $_SESSION['oauth2state'])) {
unset($_SESSION['oauth2state']);
exit('Invalid state');
} else {try {
$accessToken = $provider->getAccessToken('authorization_code',['code' => $_GET['code']]);$resourceOwner = $provider->getResourceOwner($accessToken);
...
} catch (IdentityProviderException $e) {
exit($e->getMessage());
}
```### Scopes
If you want send different scopes you must edit:
```php
$options['scope'] = array('Customer.Info','UserProfile.me');
```