https://github.com/authentiqid/oauth2-authentiq-php
Authentiq as 3rd party provider in League/oauth2-client
https://github.com/authentiqid/oauth2-authentiq-php
Last synced: about 1 month ago
JSON representation
Authentiq as 3rd party provider in League/oauth2-client
- Host: GitHub
- URL: https://github.com/authentiqid/oauth2-authentiq-php
- Owner: AuthentiqID
- License: mit
- Created: 2017-03-15T11:36:44.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-08-23T13:31:49.000Z (almost 9 years ago)
- Last Synced: 2025-01-06T02:27:06.179Z (over 1 year ago)
- Language: PHP
- Homepage: https://www.authentiq.com/developers/
- Size: 14.6 KB
- Stars: 1
- Watchers: 5
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Authentiq Provider for OAuth 2.0 Client
This package provides [Authentiq](https://www.authentiq.com/developers/?utm_source=github&utm_medium=readme&utm_campaign=oauth2-authentiq-php) support for the PHP League's [OAuth 2.0 Client](https://github.com/thephpleague/oauth2-client).
## Installation
To install, use composer:
```
composer require authentiq/oauth2-authentiq
```
## Usage
Usage is the same as The League's OAuth client, using `Authentiq\OAuth2\Client\Provider\Authentiq` as the provider.
### Authorization Code Flow
```php
$provider = new Authentiq\OAuth2\Client\Provider\Authentiq([
'clientId' => 'authentiq-client-id',
'clientSecret' => 'authentiq-client-secret',
'redirectUri' => 'your-callback-url',
'scope' => 'openid email~rs phone~r aq:name aq:push'
]);
// If we don't have an authorization code then get one
if (!isset($_GET['code'])) {
// Fetch the authorization URL from the provider; this returns the
// urlAuthorize option and generates and applies any necessary parameters
// (e.g. state).
$authorizationUrl = $provider->getAuthorizationUrl();
// Get the state generated for you and store it to the session.
$_SESSION['oauth2state'] = $provider->getState();
// Redirect the user to the authorization URL.
header('Location: ' . $authorizationUrl);
exit;
// Check given state against previously stored one to mitigate CSRF attack
} elseif (empty($_GET['state']) || (isset($_SESSION['oauth2state']) && $_GET['state'] !== $_SESSION['oauth2state'])) {
if (isset($_SESSION['oauth2state'])) {
unset($_SESSION['oauth2state']);
}
exit('Invalid state');
} else {
try {
// Try to get an the IdToken using the authorization code grant.
$idToken = $provider->getAccessToken('authorization_code', [
'code' => $_GET['code']
]);
// Using the ID token, create the resource owner.
$resourceOwner = $provider->getResourceOwner($idToken);
// Now the $resourceOwner contains all the user info you need to create the user,
// store the unique user id from the sub
// or present the info you asked for.
} catch (\League\OAuth2\Client\Provider\Exception\IdentityProviderException $e) {
// Failed to get the access token or user details.
exit($e->getMessage());
}
}
```
## Refreshing a Token
Authentiq's OAuth implementation does not use refresh tokens.