为实现统一身份认证引入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');
当执行到 phpCAS::client($casVersion, $casHost, $casPort, $casContext, $serviceUrl,false);时,Worker进程退出,报错如下:
Worker[814111] process terminated