Laravel 基于 SAML 的单点登录

SAML based SSO with Laravel

我正在为 php 网络应用程序之一实施基于 SAML 的 SSO。我正在使用 google 作为 IDP。我已经使用 Laravel 5 - Saml2 plugin and configured as per the steps given into it's documentation. I also added this app in google admin console as SAML app using the steps given here 并在 saml2_settings.php 中配置了 entityId 和 acs url。但是我无法配置 x509cert 证书。当我点击登录 url 时,用户被重定向到 google 进行身份验证,但是当我输入凭据时,它不会返回到应用程序并给出以下错误:

  1. That’s an error.

Error: app_not_configured_for_user

Service is not configured for this user.

以下是我的 saml2_settings 文件:

'sp' => array(

    // Specifies constraints on the name identifier to be used to
    // represent the requested subject.
    // Take a look on lib/Saml2/Constants.php to see the NameIdFormat supported
    'NameIDFormat' => 'urn:oasis:names:tc:SAML:2.0:nameid-format:persistent',

    // Usually x509cert and privateKey of the SP are provided by files placed at
    // the certs folder. But we can also provide them with the following parameters
    'x509cert' => 'I ADDED x509certs here which I downloaded from google',
    'privateKey' => '',

    //LARAVEL - You don't need to change anything else on the sp
    // Identifier of the SP entity  (must be a URI)
    'entityId' => 'snipeit', //LARAVEL: This would be set to saml_metadata route
    // Specifies info about where and how the <AuthnResponse> message MUST be
    // returned to the requester, in this case our SP.
    'assertionConsumerService' => array(
        // URL Location where the <Response> from the IdP will be returned
        'url' => 'http://dev.sb.com/snipeit/public/account/profile', //LARAVEL: This would be set to saml_acs route
        //SAML protocol binding to be used when returning the <Response>
        //message.  Onelogin Toolkit supports for this endpoint the
        //HTTP-Redirect binding only
        'binding' => 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST',
    ),
    // Specifies info about where and how the <Logout Response> message MUST be
    // returned to the requester, in this case our SP.
    'singleLogoutService' => array(
        // URL Location where the <Response> from the IdP will be returned
        'url' => '', //LARAVEL: This would be set to saml_sls route
        // SAML protocol binding to be used when returning the <Response>
        // message.  Onelogin Toolkit supports for this endpoint the
        // HTTP-Redirect binding only
        'binding' => 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect',
    ),
),

// Identity Provider Data that we want connect with our SP
'idp' => array(
    // Identifier of the IdP entity  (must be a URI)
    'entityId' => '',
    // SSO endpoint info of the IdP. (Authentication Request protocol)
    'singleSignOnService' => array(
        // URL Target of the IdP where the SP will send the Authentication Request Message
        'url' => $idp_host,
        // SAML protocol binding to be used when returning the <Response>
        // message.  Onelogin Toolkit supports for this endpoint the
        // HTTP-POST binding only
        'binding' => 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect',
    ),
    // SLO endpoint info of the IdP.
    'singleLogoutService' => array(
        // URL Location of the IdP where the SP will send the SLO Request
        'url' => $idp_host . '/saml2/idp/SingleLogoutService.php',
        // SAML protocol binding to be used when returning the <Response>
        // message.  Onelogin Toolkit supports for this endpoint the
        // HTTP-Redirect binding only
        'binding' => 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect',
    ),
    // Public x509 certificate of the IdP
    'x509cert' => 'SAME CERTIFICATES I ADDED HERE AS WELL',        /*
     *  Instead of use the whole x509cert you can use a fingerprint
     *  (openssl x509 -noout -fingerprint -in "idp.crt" to generate it)
     */
    // 'certFingerprint' => '',
),

谁能帮帮我。

'sp' => array(

'x509cert' => 'I ADDED x509certs here which I downloaded from google',
'privateKey' => '',

您正在使用 Google 作为 IdP,那么为什么要在 sp 部分使用 google public 证书?

如果您打算签署 SP 发送的 SAML 消息,那么您需要将自己的 cert/private 密钥放在那里。您可以使用此工具生成自签名证书:https://www.samltool.com/self_signed_certs.php

如果您对某些设置字段有疑问,请查看 Lavarel SAML 插件的文档,还要查看插件使用的 SAML 工具包 documentation of php-saml

为了调试正在发生的事情,我还建议您使用浏览器扩展来记录您的 SAML 消息,例如使用 SAML Tracer 并查看将通知您可能的错误的响应状态。