stolfam / ms-azure-sso-php
Microsoft Azure SSO 认证的简单易用 PHP 连接器
1.0.4
2024-09-24 13:07 UTC
Requires
- php: >= 8.0.0
- stolfam/data-storage-php: ^1.0
Requires (Dev)
- nette/tester: ^2.3
README
安装
composer require stolfam/ms-azure-sso-php
Nette
Neon 配置
parameters:
microsoft:
azure:
loginBaseUri: https://login.microsoftonline.com
apiBaseUri: https://login.windows.net
appId: xxx
clientSecret: xxx
tenantId: xxx
redirectUri: https://
refreshTokenRotationTime: 60
refreshTokenKey: storageKey
services:
- Stolfam\MS\Azure\Client(%microsoft.azure%)
使用
重定向到登录 URL
$client = new Client($arrayArgs);
$state = "abc123";
$loginUrl = $client->getLoginUrl($state)
// redirect to $loginUrl to invoke user authentication with MS AZure
处理返回的授权码
$code = $_GET['code'];
$state = $_GET['state']; // abc123
// set callback
$client->onAuthSuccess[] = function(UserProfile $userProfile) {
// authentication successful
// persist user data where you need
echo $userProfile->id;
echo $userProfile->name;
echo $userProfile->email;
};
if($client->authorize($code)) {
// success
// i.e. redirect back to original page before login invoked
}
处理过期登录
if(!$client->isSessionValid()) {
// session expired
// try to re-authorize
$client->invokeReAuthorization();
}