dev-master
9999999-devOauth2 Azure login
MIT
The Requires
by Vinh Hoang
php azure
1.0.1
1.0.1.0Oauth2 Azure login
MIT
The Requires
by Vinh Hoang
php azure
Wallogit.com
2017 © Pedro Peláez
Oauth2 Azure login
This package is built based on this source Azure Active Directory Provider for OAuth 2.0 Client., (*1)
To install, use composer:, (*2)
composer require vinhhoang/oauth2-azure
After installing the Socialite library, register the VinhHoang\OAuth2\AzureServiceProvider in your config/app.php configuration file:, (*3)
'providers' => [
// Other service providers...
VinhHoang\OAuth2\AzureServiceProvider::class,
],
Also, add the Azure facade to the aliases array in your app configuration file:, (*4)
'Azure' => VinhHoang\OAuth2\Facades\Azure::class
Then, run this comment, (*5)
php artisan vendor:publish --provider="VinhHoang\OAuth2\AzureServiceProvider", (*6)
You will also need to add credentials for the OAuth services your application utilizes. These credentials should be placed in your config/oauth2azure.php configuration file:, (*7)
[
'clientId' => 'your-client-id',
'clientSecret' => 'your-client-secret',
'redirectUri' => 'your-redirect-uri',
'tenant' => 'your-tenant',
],
<?php
namespace App\Http\Controllers;
use Azure;
class LoginController
{
public function login()
{
return Azure::redirect();
}
public function handleCallback()
{
$token = Azure::getAccessToken('authorization_code', [
'code' => $_GET['code'],
'resource' => 'https://graph.windows.net',
]);
try {
// We got an access token, let's now get the user's details
$me = Azure::get("me", $token);
} catch (\Exception $e) {
//
}
// Use this to interact with an API on the users behalf
echo $token->getToken();
}
public function logout()
{
$redirect_url = "http://example.com";
return redirect(Azure::getLogoutUrl($redirect_url));
}
}
You will need to define routes to your controller methods:, (*8)
Route::get('login', 'LoginController@login');
Route::get('login/callback', 'LoginController@handleCallback');
Route::get('logout', 'LoginController@logout');
With version 1.1.0 and onward, the Resource Owner information is parsed from the JWT passed in access_token by Azure Active Directory. It exposes few attributes and one function., (*9)
Example:, (*10)
$resourceOwner = Azure::getResourceOwner($token); echo 'Hello, '.$resourceOwner->getFirstName().'!';
The exposed attributes and function are:
- getId() - Gets user's object id - unique for each user
- getEmail() - Gets user's email - unique for each user
- getFirstName() - Gets user's first name
- getLastName() - Gets user's family name/surname
- getTenantId() - Gets id of tenant which the user is member of
- getUpn() - Gets user's User Principal Name, which can be also used as user's e-mail address
- claim($name) - Gets any other claim (specified as $name) from the JWT, full list can be found here, (*11)
Oauth2 Azure login
MIT
php azure
Oauth2 Azure login
MIT
php azure