首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >从Azure AD到SAML 2连接TYPO3 fe_users的最佳方法是什么?

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

Stack Overflow用户
提问于 2019-01-15 07:29:12
回答 2查看 1.4K关注 0票数 3

我需要在TYPO3内部网上实现SSO,其中fe_users与Azure同步。平台将在V9中运行。是否有我还没有找到的兼容的扩展?如果不是,用SAML2.0实现自动身份验证的最佳方法是什么?谢谢你,瑞秋

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-03-02 06:59:27

感谢@Rakel (和其他人),我终于解决了SAML身份验证需求。不过,我还是使用了一种稍微不同、更直接的方法,然后在她的解决方案中进行了描述。

我使用身份验证服务来实现SAML登录进程。为了处理SAML登录本身,我使用了库SimpleSamlPHP,这是我真正推荐的。它非常简单,并且提供了测试SAML配置的前端,无需处理TYPO3就可以方便地测试身份提供者(Idp)配置。

有关详细信息,请查看以下内容:https://docs.typo3.org/m/typo3/reference-coreapi/master/en-us/ApiOverview/Authentication/Index.html

首先,您需要创建一个扩展TYPO3\CMS\Core\Authentication\AuthenticationService.的类该类必须实现方法"getUser""authUser"

代码语言:javascript
运行
复制
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“中注册服务。

代码语言:javascript
运行
复制
...
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"应该返回一个数组,该数组保存要登录的FeUser及其所有参数。

方法"authUser"只返回200或0。查看这个链接,了解要返回的数字:https://docs.typo3.org/m/typo3/reference-services/7.6/en-us/Authentication/Index.html#authentication-service-chain在返回"200“之后,创建了FeUser对象,并将用户登录。不需要自己摆弄全球的“‘TSFE”。这是一个巨大的好处,因为它使您的代码更短,更容易阅读。

尽管如此,我还是从阅读所有的文档和响应以及TYPO3频道上学到了很多东西。感谢所有帮助我的人。非常感谢。

票数 1
EN

Stack Overflow用户

发布于 2020-01-30 10:30:03

是的我们解决了这个问题。我们使用SimpleSAMLphp实现身份验证,下面是一个很好的教程:https://www.lewisroberts.com/2015/09/05/single-sign-on-to-azure-ad-using-simplesamlphp/

当您能够连接时,您只需实现一个进程,当您获得saml用户属性时,就可以自动连接一个fe_user。

以下是对这一过程的简化总结:

如果我们在没有经过身份验证的情况下到达TYPO3站点url,那么重定向到如下脚本:

代码语言:javascript
运行
复制
// 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);
}

下面是auth页面所做工作的一个简单摘要:

代码语言:javascript
运行
复制
//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;

    }
}

干杯,瑞秋

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54194370

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档