eutkin/aadphp
Composer 安装命令:
composer require eutkin/aadphp
包简介
Microsoft Azure Active Directory Authentication Library (AAD) for PHP
README 文档
README
This sample contains a PHP libary for accessing Azure Active Directory and a sample app that demonstrates the functionality of that library as well as the new Microsoft School Data Sync API.
Usage
Construct an HttpClient object:
$httpclient = new \microsoft\aadphp\HttpClient;
Construct a storage object. A storage object needs to implement the \microsoft\aadphp\OIDC\StorageInterface interface. Currently, two sample implementations are available under microsoft\aadphp\OIDC\StorageProviders namespace - SQLite and Session, but you may need to implement this class yourself based on your storage needs or environment.
Initialize SQLite storage provider (as shown in samples folder):
$storage = new \microsoft\aadphp\OIDC\StorageInterface\SQLite(__DIR__.'/storagedb.sqlite');
or initialize the Session storage provider:
$storage = new \microsoft\aadphp\OIDC\StorageInterface\Session();
Construct the AzureAD client class using the $httpclient and $storage instances.
$client = new \microsoft\aadphp\AAD\Client($httpclient, $storage);
Set your client ID, client secret, and redirect URI.
$client->set_clientid($clientid);
$client->set_clientsecret($clientsecret);
$client->set_redirecturi($redirecturi);
You client is now ready to use.
To initiate an authorization request:
$client->authrequest();
To handle an authorization request response (this should be in your redirect URI page):
list($idtoken, $tokenparams, $stateparams) = $client->handle_auth_response($_REQUEST);
To perform a resource-owner credentials request:
$returned = $client->rocredsrequest($_POST['username'], $_POST['password']);
$idtoken = \microsoft\aadphp\AAD\IDToken::instance_from_encoded($returned['id_token']);
To get user information from an IDToken, call ->claim() on the $idtoken object. This returns OpenID Connect claims:
$idtoken->claim('name');
$idtoken->claim('upn');
Authorization Code Flows
There are 3 authorization code flows one can implement with this library.
1. Authorization code flow:
This is the common 3 legged OAuth2 flow. This will redirect you to the Azure AD login page if you aren't already logged in to Azure AD and take you through the login process. Example: To initate a authorization request call the function $client->authrequest(). The client is set to use this method as default.
$client->authrequest();
This will perform an authorization request by redirecting resource owner's user agent to authentication endpoint. Your request will be processed and response will be served in the redirect uri you have set earlier in config.php. To handle the response call the function $client->handle_auth_response($_REQUEST).
list($idtoken, $tokenparams, $stateparams) = $client->handle_auth_response($_REQUEST);
Now, $idtoken has the object of JWT token(you can claim the user information using this token), $tokenparams contain array of token parameters i.e. access_token, refresh_token, $stateparams contain state parameters.
2. Hybrid code flow:
This is the quicker ID Token OAuth2 flow. This will redirect you to the Azure AD login page if you haven't already logged in to Azure AD and take you through the login process. Example: To initate a hybrid flow request set the client to use hybrid flow then call the function $client->authrequest().It will then return you the list of list of IDToken object and stored state parameters.
$client->set_authflow('hybrid');
$client->authrequest();
This will perform an authorization request by redirecting resource owner's user agent to authentication endpoint. Your request will be processed and response will be served in the redirect uri you have set earlier in config.php. To handle the response call the function $client->handle_auth_response($_REQUEST).
list($idtoken, $stateparams) = $client->handle_id_token($_REQUEST);
Now, $idtoken has the object of JWT token(you can claim the user information using this token), $stateparams contain state parameters.
3. Resource Owner Password Credentials Grant:
This allows you to enter Azure AD login credentials directly in the login form and have authentication happen behind the scenes. You will not be redirected to Azure AD to log in. To perform a resource-owner credentials request:
$returned = $client->rocredsrequest($_POST['username'], $_POST['password']);
This will perform an authorization request by sending the user credentials to token endpoint. The response($returned) contain array of token parameters i.e. id_token, access_token, refresh_token.
Samples and Documentation
The samples folder contains a sample implementation of the library demonstrating basic authentication in several different ways.
Community Help and Support
We leverage Stack Overflow to work with the community on supporting Azure Active Directory and its SDKs, including this one! We highly recommend you ask your questions on Stack Overflow (we're all on there!) Also browse existing issues to see if someone has had your question before.
We recommend you use the "adal" tag so we can see it! Here is the latest Q&A on Stack Overflow for AAD: http://stackoverflow.com/questions/tagged/adal
eutkin/aadphp 适用场景与选型建议
eutkin/aadphp 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.05k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2017 年 05 月 17 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「oauth2」 「SSO」 「azure」 「identity」 「single sign on」 「oidc」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 eutkin/aadphp 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 eutkin/aadphp 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 eutkin/aadphp 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Small library to access Microsoft Windows Azure Blob Storage with a Service or a StreamWrapper.
A lightweight and powerful OAuth 2.0 authorization and resource server library with support for all the core specification grants. This library will allow you to secure your API with OAuth and allow your applications users to approve apps that want to access their data from your API.
Adds Silverstripe Flysystem support for using the Azure Blob adapter
Email Toolkit Plugin for CakePHP
Laravel 5 Queue Driver for Microsoft Azure Storage Queue
Laravel Azure storage service provider
统计信息
- 总下载量: 4.05k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 40
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-05-17