使用 SAML 2 从 Azure AD 连接 TYPO3 fe_users 的最佳方法是什么?

What is the best way to connect TYPO3 fe_users from an Azure AD with SAML 2?

我需要在 TYPO3 Intranet 上实施 SSO,其中 fe_users 从 Azure AD 同步。该平台将采用 V9。 是否有我尚未找到的兼容扩展? 如果不是,使用 SAML 2.0 实现自动身份验证的最佳方法是什么? 提前致谢, 雷切尔

是的,我们解决了这个要求。我们使用 SimpleSAMLphp 来实现身份验证,遵循这个很棒的教程: https://www.lewisroberts.com/2015/09/05/single-sign-on-to-azure-ad-using-simplesamlphp/

当您能够连接时,您只需实施一个过程以在获得 saml 用户属性时自动连接 fe_user。

这里是该过程的简化摘要:

如果我们到达一个 TYPO3 站点 url 并且没有经过身份验证然后重定向到这样的脚本:

// SimpleSamlPHP library
require_once (dirname(__FILE__) . /../../../../../../simplesamlphp/lib/_autoload.php');

//instanciation of a simple authentication
$as = new SimpleSAML_Auth_Simple('default-sp');

//requires authentication from Office 365
$as->requireAuth();

//retrieving information from the logged-in user
$attributes = $as->getAttributes();

//retrieve original url
$returnURL = $_GET['returnURL'];

//if a user is well connected
if($attributes){

    //redirection to the TYPO3 site with the username
    header('Location: /auth/?samlUident='.$attributes['http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name'][0].'&recupURL='.$returnURL);
}

下面是授权页面功能的简要总结:

//if a get saml is in the url
if(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('samlUident')){

    //recovering username for TYPO3 authentication
    $loginData = array(
        'uname' => \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('samlUident'), //username
        'status' => 'login'
    );

    //TYPO3 session creation
    $frontendUserAuthentication = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication');
    $frontendUserAuthentication->checkPid = false;
    $info = $frontendUserAuthentication->getAuthInfoArray();

    $user_db = $frontendUserAuthentication->fetchUserRecord($info['db_user'], $loginData['uname']);

    //if a user exists
    if ($user_db){

        //authentication
        $GLOBALS['TSFE']->fe_user->forceSetCookie = TRUE;
        $GLOBALS['TSFE']->fe_user->dontSetCookie = false;
        $GLOBALS['TSFE']->fe_user->start();
        $GLOBALS['TSFE']->fe_user->createUserSession($user_db);
        $GLOBALS['TSFE']->fe_user->user = $user_db;
        $GLOBALS['TSFE']->fe_user->setAndSaveSessionData('dummy', TRUE);
        $GLOBALS['TSFE']->fe_user->loginUser = 1;

    }
}

干杯, 雷切尔

感谢@Rakel(和其他人),我终于解决了我的 SAML 身份验证要求。我仍然使用了一种略有不同且更直接的方法,然后在她的解决方案中进行了描述。

我使用身份验证服务来实施 SAML 登录过程。 为了处理 SAML 登录本身,我使用了库 SimpleSamlPHP,我非常推荐它。它非常简单,提供的用于测试 SAML 配置的前端非常方便地测试身份提供程序 (Idp) 配置而无需处理 TYPO3。

详情请看这里:https://docs.typo3.org/m/typo3/reference-coreapi/master/en-us/ApiOverview/Authentication/Index.html

首先您需要创建一个 class 来扩展 TYPO3\CMS\Core\Authentication\AuthenticationService。 class 必须实现方法 "getUser""authUser".

namespace Vendor\Extension\Service;

use SimpleSAML\Auth\Simple;
use TYPO3\CMS\Core\Authentication\AuthenticationService;
class SamlAuth extends AuthenticationService
{

    public function getUser() {
        // Create new Simple Auth with SimpleSamlPHP
        $as = new Simple($config['sp']);
        // Require authentication, this redirects you to the Idp and then comes back
        $as->requireAuth();
        // Get the attributes provides by your Idp
        $attributes = $as->getAttributes();
        // Please consult the API for details on fetchUserRecord
        // Also the SAML attributes may vary depending on your Idp implementation
        $user = $this->fetchUserRecord($attributes['http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name'];
    }

    public function authUser(array $user): int {
        return is_array($user) ? 200 : 0;
    }
}

然后您需要在您的扩展中注册该服务"ext_localconf.php"。

...
TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addService(
      'my_extension',
      'auth',
      Vendor\Extension\Service\SamlAuth::class,
      [
          'title' => 'Saml Authentication for Frontend Users',
          'description' => 'Authenticates FeUsers via Saml',
          'subtype' => 'authUserFE,getUserFE',
          'available' => true,
          'priority' => 80,
          'quality' => 80,
          'os' => '',
          'exec' => '',
          'className' => Vendor\Extension\Service\SamlAuth::class
      ]
    );
...

请注意:

  • 这只是我最终代码的过度简化版本。只是为了让你开始这个想法。
  • 您还需要正确配置 SimpleSamlPHP。有关详细信息,请查看他们的文档。

方法"getUser" 应该return 一个数组,其中包含要在FeUser 中记录的所有参数。

方法"authUser"只是为了return200或0。看看这个link就知道有哪些数字了至 return:https://docs.typo3.org/m/typo3/reference-services/7.6/en-us/Authentication/Index.html#authentication-service-chain 在 returning "200" 之后,创建了 FeUser 对象并登录了用户。无需自己 fiddle 与 $GLOBALS['TSFE'] 周旋。这是一个巨大的好处,因为它使您的代码更短且更易于阅读。

尽管如此,我还是通过阅读此处和 Slacks TYPO3 频道上的所有文档和回复学到了很多东西。 感谢所有帮助过我的人。非常感谢。