Wallogit.com
2017 © Pedro Peláez

This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License.
, (*1)
This Package can be used to connect to an OAuth2-Service and fetch OAuth2 restricted resources. this is Laravel OAuth rapper for https://github.com/adoy/PHP-OAuth2 , (*2)
Update your composer.json "require"-Section with this line:
, (*3)
"mahfuz05/laravel-oauth2": "dev-master"
After adding this line, run the following command: , (*4)
composer install
or
composer update
You need to publish the configuration file of this package with: , (*5)
php artisan config:publish mahfuz05/laravel-oauth2
The Config-File path is app/config/mahfuz05/laravel-oauth2/config.php
Here you have to add/modify the values for your purpose.
[client.id] - Client-ID of your Application
[client.secret] - Client-Secret of your Application
[scopes] - Scopes for your Application (comma separated)
, (*6)
After modifying the Package-Config, update the app/config/app.php
Modify your providers and aliases section, with your preferred alias:
'providers' => 'Mahfuz05\LaravelOauth2\LaravelOauth2ServiceProvider'
'aliases' => 'LaravelOauth2' => 'Mahfuz05\LaravelOauth2\Facades\LaravelOauth2'
, (*7)
LaravelOauth2::fetchAccessToken('http://3rd.party.com/api/access_token', 'password', array(
'username' => $credentials['username'],
'password' => $credentials['password'],
'scope' => Config::get('oauth2-client::scopes'),
));
$result = LaravelOauth2::fetch('http://3rd.party.com/api/restriced/resource');
if (!isset($_GET['code']))
{
$auth_url = LaravelOauth2::getAuthenticationUrl($this->url, $this->redirectUri);
header('Location: ' . $auth_url);
die('Redirect');
}
else
{
$params = array('code' => $_GET['code'], 'redirect_uri' => $this->redirectUri);
$response = LaravelOauth2::getAccessToken($this->token_url, 'authorization_code', $params);
//get Access Token and store it
LaravelOauth2::setAccessToken($response['result']['access_token']);
$token = $response['result']['access_token'];
//get all customers
$response = LaravelOauth2::fetch('https://api.debitoor.com/api/v1.0/customers');
}