我必须更新针对 ADFS 服务器进行身份验证的自定义身份验证服务。该服务在 TYPO3 v11 上运行良好,但在 TYPO3 v12 上则不再运行。不知何故,我的
authUser(array $user)
类的方法 MyAuthService
根本没有被调用。
在我的
ext_localconf.php
中我注册了服务:
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addService(
'my_ext',
'auth',
\Vendor\Extension\Authentication\MyAuthService::class,
[
'title' => 'ADFS Authentication',
'description' => 'Authentication with a Microsoft ADFS',
'subtype' => 'authUserFE,getUserFE,authUserBE,getUserBE',
'available' => true,
'priority' => 80,
'quality' => 80,
'os' => '',
'exec' => '',
'className' => \Vendor\Extension\Authentication\MyAuthService::class
]
);
MyAuthService.php
namespace Vendor\Extension\Authentication;
use TYPO3\CMS\Core\Authentication\AbstractAuthenticationService;
class MyAuthService extends AbstractAuthenticationService
{
public function authUser(array $user): int
{
// This is never called...
echo 'authUser';
exit;
}
public function getUser()
{
// redirect to ADFS server and do authentication
}
}
在方法
getUser()
中正确触发了到ADFS服务器的重定向。在与 ADFS 服务器进行身份验证后,它返回到我的 TYPO3,并发布了正确的数据。从 ADFS 服务器返回后,登录失败,TYPO3 再次显示登录屏幕。
我缺少什么才能让我的身份验证服务再次在 TYPO3 v12 中工作?
您必须确保有有效的请求令牌。由于您正在处理 SSO 回调,因此您没有任何请求令牌,必须手动生成它。
为此,请为
BeforeRequestTokenProcessedEvent
事件实现一个事件侦听器。在事件监听器中,按照文档中所示设置请求令牌https://docs.typo3.org/m/typo3/reference-coreapi/main/en-us/ApiOverview/Events/Events/Core/Authentication/BeforeRequestTokenProcessedEvent .html#beforerequesttokenprocessedevent
$event->setRequestToken(
RequestToken::create('core/user-auth/' . strtolower($user->loginType))
);