https://github.com/alexmasterov/oauth2-superjob
SuperJob.ru Provider for the OAuth 2.0 Client
https://github.com/alexmasterov/oauth2-superjob
league-oauth2 oauth2 oauth2-provider oauth2-superjob
Last synced: 6 months ago
JSON representation
SuperJob.ru Provider for the OAuth 2.0 Client
- Host: GitHub
- URL: https://github.com/alexmasterov/oauth2-superjob
- Owner: AlexMasterov
- License: mit
- Created: 2016-11-26T18:49:46.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2018-02-13T03:32:27.000Z (over 8 years ago)
- Last Synced: 2024-04-26T02:41:28.992Z (about 2 years ago)
- Topics: league-oauth2, oauth2, oauth2-provider, oauth2-superjob
- Language: PHP
- Homepage:
- Size: 13.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SuperJob.ru Provider for OAuth 2.0 Client
[](https://packagist.org/packages/alexmasterov/oauth2-superjob)
[](https://github.com/AlexMasterov/oauth2-superjob/blob/master/LICENSE)
[](https://travis-ci.org/AlexMasterov/oauth2-superjob)
[](https://scrutinizer-ci.com/g/AlexMasterov/oauth2-superjob/?branch=master)
[](https://scrutinizer-ci.com/g/AlexMasterov/oauth2-superjob/?branch=master)
This package provides [SuperJob.ru](https://superjob.ru) OAuth 2.0 support for the PHP League's [OAuth 2.0 Client](https://github.com/thephpleague/oauth2-client).
## Installation
The suggested installation method is via [composer](https://getcomposer.org/):
```sh
composer require alexmasterov/oauth2-superjob
```
## Usage
### Configuration
```php
$provider = new AlexMasterov\OAuth2\Client\Provider\SuperJob([
'clientId' => '{client_id}',
'clientSecret' => '{client_secret}',
'redirectUri' => '{redirect_uri}',
'state' => '{state}',
]);
```
### Authorization
```php
if (!empty($_GET['error'])) {
// Got an error, probably user denied access
exit('Got error: ' . $_GET['error']);
}
if (empty($_GET['code'])) {
// If we don't have an authorization code then get one
$provider->authorize();
}
// Try to get an access token (using the authorization code grant)
$token = $provider->getAccessToken('authorization_code', [
'code' => $_GET['code']
]);
// Optional: Now you have a token you can look up a users profile data
try {
// We got an access token, let's now get the owner details
$ownerDetails = $provider->getResourceOwner($token);
// Use these details to create a new profile
printf('Hello, %s!', $ownerDetails->getName());
} catch (\Exception $e) {
// Failed to get user details
exit('Something went wrong: ' . $e->getMessage());
}
// Use this to interact with an API on the users behalf
echo $token->accessToken;
```