vinhhoang/oauth2-azure
最新稳定版本:v1.0.4
Composer 安装命令:
composer require vinhhoang/oauth2-azure
包简介
Oauth2 Azure login
README 文档
README
This package is built based on this source Azure Active Directory Provider for OAuth 2.0 Client.
Installation
To install, use composer:
composer require vinhhoang/oauth2-azure
Configuration
After installing the Socialite library, register the VinhHoang\OAuth2\AzureServiceProvider in your config/app.php configuration file:
'providers' => [ // Other service providers... VinhHoang\OAuth2\AzureServiceProvider::class, ],
Also, add the Azure facade to the aliases array in your app configuration file:
'Azure' => VinhHoang\OAuth2\Facades\Azure::class
Then, run this comment
php artisan vendor:publish --provider="VinhHoang\OAuth2\AzureServiceProvider"
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:
[
'clientId' => 'your-client-id',
'clientSecret' => 'your-client-secret',
'redirectUri' => 'your-redirect-uri',
'tenant' => 'your-tenant',
],
Basic Usage
<?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:
Route::get('login', 'LoginController@login'); Route::get('login/callback', 'LoginController@handleCallback'); Route::get('logout', 'LoginController@logout');
Resource Owner
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.
Example:
$resourceOwner = Azure::getResourceOwner($token); echo 'Hello, '.$resourceOwner->getFirstName().'!';
The exposed attributes and function are:
getId()- Gets user's object id - unique for each usergetEmail()- Gets user's email - unique for each usergetFirstName()- Gets user's first namegetLastName()- Gets user's family name/surnamegetTenantId()- Gets id of tenant which the user is member ofgetUpn()- Gets user's User Principal Name, which can be also used as user's e-mail addressclaim($name)- Gets any other claim (specified as$name) from the JWT, full list can be found here
统计信息
- 总下载量: 3.59k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-08-29