单一登录使用Laravel上的SimpleSamlPhp包装器

Dan*_*elo 2 php simplesamlphp laravel-5.2

在我的laravel应用程序中实现单点登录.我决定使用这个插件https://github.com/aacotroneo/laravel-saml2,它基本上是着名的SimpleSamlPhp的包装器.

我通过作曲家和给定的信息下载了代码 Remember that you don't need to implement those routes, but you'll need to add them to your IDP configuration. For example, if you use simplesamlphp, add the following to /metadata/sp-remote.php

$metadata['http://laravel_url/saml/metadata'] = array(
 'AssertionConsumerService' => 'http://laravel_url/saml/acs',
 'SingleLogoutService' => 'http://laravel_url/saml/sls',
 //the following two affect what the $Saml2user->getUserId() will return
 'NameIDFormat' => 'urn:oasis:names:tc:SAML:2.0:nameid-format:persistent',
 'simplesaml.nameidattribute' => 'uid'  
);
Run Code Online (Sandbox Code Playgroud)

我找不到metadata/sp-remote.php,有什么想法吗?而据http://laravel_url/saml/acs而言,我需要在服务器上部署SAML?因为此时插件代码vendors处于laravel核心架构代码层次结构中.

Fix*_*pec 9

首先是一些背景:

任何SAML交互都有两个部分 - 身份提供者("IDP")和服务提供者("SP").如果您愿意,IDP是主身份验证器,各种应用程序(SP)连接到该身份验证器.

这个想法是用户访问您的应用程序,该应用程序又作为服务提供商与身份提供商进行通信以获取您的凭据.而且由于多个应用程序/ SP会对同一个IDP进行竞争,因此您可以获得单点登录的好处.

在设置阶段,在SP和IDP之间交换元数据配置以在它们之间建立信任.这不是用户级数据 - 它是允许他们交谈的应用程序级数据.

好.那么现在问你的问题:

您正在使用的软件包允许您的Laravel应用程序与IDP通信,但在此之前您需要交换一些元数据.您应用的元数据是上面的代码段.这需要进入IDP配置,您可以在这里找到它metadata/sp-remote(或者更准确地说metadata/saml20-sp-remote,这是您将其粘贴的位置).

如果您还没有这样做,我建议您使用[ https://simplesamlphp.org/docs/stable/][1]作为IDP,因为Laravel软件包几乎可以使用它.

最后一个提示:如果您使用的是SAML2,那么我发现您需要更改元数据键以引用saml2而不是上面的saml.即$metadata['http://laravel_url/saml2/metadata']不是$metadata['http://laravel_url/saml/metadata']


Dan*_*elo 1

我希望这会帮助其他人。我saml2_settings.phpconfig文件夹里添加了。

更新了路线:

'logoutRoute' => '/logout',
'loginRoute' => '/homepage',
'errorRoute' => '/error',
Run Code Online (Sandbox Code Playgroud)

更新x509cert(publickey.cer)和privateKey

更新了'entityId',添加了元数据xml的url。更新了文件singleLogoutService中所需的详细信息saml2_settings.php

添加了两个监听器 1) 用于登录事件 2) 用于注销事件

像这样更新路由文件:

\Illuminate\Support\Facades\Event::listen('Aacotroneo\Saml2\Events\Saml2LogoutEvent', function ($event) {
    \Illuminate\Support\Facades\Auth::logout();
    \Illuminate\Support\Facades\Session::save();
    return redirect("login");
});

\Illuminate\Support\Facades\Event::listen('Aacotroneo\Saml2\Events\Saml2LoginEvent', function (\Aacotroneo\Saml2\Events\Saml2LoginEvent $event) {

    $user = $event->getSaml2User();
    $userData = [
        'id' => $user->getUserId(),
        'attributes' => $user->getAttributes(),
        'assertion' => $user->getRawSamlAssertion()
    ];


      // add the login for auto login based on your settings
    /// REDIRECT the user to homepage
    }
});
Run Code Online (Sandbox Code Playgroud)