简体   繁体   English

为 TYPO3 后端验证远程验证的用户凭据

[英]Authenticating remotely validated user credentials for TYPO3 backend

I need a bit help in login in a backend user whos credentials have been verified by a remote server.我需要一些帮助来登录一个已通过远程服务器验证凭据的后端用户。 The actual user and all its permissions are set in TYPO3, but the password is stored on a remote server.实际用户及其所有权限都在 TYPO3 中设置,但密码存储在远程服务器上。

So far I've created a small extension, that redirects the backend login to my Login provider:到目前为止,我已经创建了一个小扩展,它将后端登录重定向到我的登录提供程序:

$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['backend']['loginProviders'][1433416747]['provider'] = \User\MyExtension\Hooks\LoginProvider::class;

where I check the username and password combination on the remote server.我在这里检查远程服务器上的用户名和密码组合。

class LoginProvider implements LoginProviderInterface
{
    public function render(StandaloneView $view, PageRenderer $pageRenderer, LoginController $loginController)
    {

        $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName('EXT:my_extension/Resources/Private/Templates/BELogin.html'));

        // Check request
        if (
            isset($_POST['login_status'])
            && $_POST['login_status'] == 'login'
            && !empty($_POST['username'])
            && !empty($_POST['p_field'])
            && $_POST['interface'] == 'backend'
        ) {
            // Get EXT connection data from settings
            $EXT_CONFIG       = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['my_extension']);
            $this->extServer = $EXT_CONFIG['extServer'];
            $this->extDC     = $EXT_CONFIG['extDC'];

            // Assign received login data
            $this->username = GeneralUtility::_GP('username');
            $this->password = GeneralUtility::_GP('p_field');

            // Try to authenticate
            if ($this->checkCredentials()) {
                // @TODO: Need to log in the verified user credentials!
            }
        }
    }

    private function checkCredentials()
    {
        // Check if local user exists
        $local = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows("uid", "be_users", "username='{$this->username}' AND disable=0") ?? 0;

        // Check credentials and recieve user object if correct, or false if wrong
        if ($local > 0) {
            $ext           = new EXT($this->extServer, $this->extDC);
            $this->extUser = $ext->authorize($this->username, $this->password);
        }

        return $this->extUser ? true : false;
    }
}

Now I would need to log in the verified user, but can't understand how.现在我需要登录经过验证的用户,但不明白如何登录。

PS: I already found BackendUserAuthentication , but that only works once the user is already authenticated (or I don't know how to use). PS:我已经找到BackendUserAuthentication ,但只有在用户已经通过身份验证(或者我不知道如何使用)后才有效。

A LoginProvider is only for rendering a different login form (eg for openID, which does not need a password field). LoginProvider仅用于呈现不同的登录表单(例如,对于不需要密码字段的 openID)。

You need to implement an authentication service: https://docs.typo3.org/typo3cms/Typo3ServicesReference/Authentication/Index.html你需要实现一个认证服务: https : //docs.typo3.org/typo3cms/Typo3ServicesReference/Authentication/Index.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM