為實現(xiàn)統(tǒng)一身份認證引入apereo/phpcas,
通過composer require apereo/phpcas 安裝
$casHost = config('plugin.sso.cas.host');
$casPort = config('plugin.sso.cas.port');
$casContext = config('plugin.sso.cas.context');
$casValidateCert = config('plugin.sso.cas.validate_cert', true);
$casVersion = config('plugin.sso.cas.version', '3.0');
$serviceUrl = "http://" . $request->host() . $request->path();
// 初始化CAS客戶端
phpCAS::client($casVersion, $casHost, $casPort, $casContext, $serviceUrl,false);
if ($casValidateCert) {
phpCAS::setCasServerCACert(config('plugin.sso.cas.cert_path'));
} else {
phpCAS::setNoCasServerValidation();
}
phpCAS::forceAuthentication();
$username = phpCAS::getUser();
if (empty($username)) {
throw new \Exception('無法獲取CAS用戶名');
}
$attributes = phpCAS::getAttributes();
\Log::info('CAS用戶屬性', $attributes);
$userData = [
'username' => $username,
'nickname' => $username,
'avatar' => '',
'email' => $attributes['email'] ?? '',
'mobile' => $attributes['mobile'] ?? '',
'login_at' => date('Y-m-d H:i:s'),
];
$request->session()->put('admin', $userData);
return redirect('/account/index');
當執(zhí)行到 phpCAS::client($casVersion, $casHost, $casPort, $casContext, $serviceUrl,false);時,Worker進程退出,報錯如下:
Worker[814111] process terminated