Google Cloud Identity Platform(CICP)SAML工作流程失败

问题描述 投票:1回答:1

背景

使用具有以下配置的Firebase身份验证和SAML身份验证提供程序:

const config = {
    apiKey: "AIzaSy...",
    authDomain: "example-app.firebaseapp.com",
};

firebase.initializeApp(config);

const provider = new firebase.auth.SAMLAuthProvider('saml.example-idp');

function saml() {
    firebase.auth().signInWithRedirect(provider)
        .then((result) => {
            console.log(result);
        })
        .catch((error) => {
            console.log(error);
        });
}

SAML上游的CICP配置具有服务提供商:我们的实体ID和ACS配置为我们的CICP https://example-app.firebaseapp.com/__/auth/handler

我期望会发生什么

为了能够在signInWithRedirect()的Promise的then中设置断点,并查看已通过身份验证的用户。

实际发生的事情

流被重定向到IdP并进行身份验证。

IdP发出带有自动加载提交和multipart/form-data格式的重定向发布页面:

  • Content-Disposition:表单数据; name = SAMLResponse-包含base64编码的签名SAMLResponse
  • Content-Disposition:表单数据;name = RelayState-包含来自SAML流的中继状态
  • Content-Disposition:表单数据; name =“ ssourl”-包含firebase项目身份验证处理程序URI

这继而使CICP渲染并返回带有已设置脚本的页面

var POST_BODY=""------WebKitFormBoundary9bn7AOpnZiIRk9qZ\r\nContent....."

即而不是解析表单主体并提取SAMLResponse字段,而是将整个Request.body重播到脚本中,然后调用fireauth.oauthhelper.widget.initialize();

这显然失败,因为该往返然后尝试将整个响应正文作为查询字符串发布到/__/auth/handler端点。

我怀疑此链中缺少一个简单的配置项,因为所有流程对我来说都是正常的,直到多部分表单数据被推入POST_BODY,然后阻止将SAML令牌转换成OAuth令牌。

问题

此(已编辑的)设置中哪个配置项不正确,以及用其替换的值的正确推导是什么?

google-cloud-platform firebase-authentication saml-2.0 google-cloud-identity
1个回答
0
投票

[SAML也许还有其他技术问题,但是至少在使用sign-in方法的方式上存在一个不连贯的地方。

根据(官方文档)[https://cloud.google.com/identity-platform/docs/how-to-enable-application-for-saml#handle-signin-with-client-sdk],您有2个登录选项:

1)有弹出窗口

在这种情况下,您可以使用Promise通过user credential方法检索sign-in

firebase.auth().signInWithPopup(provider)
    .then((result) => {
      // User is signed in.
      // Identity provider data available in result.additionalUserInfo.profile,
      // or from the user's ID token obtained via result.user.getIdToken()
      // as an object in the firebase.sign_in_attributes custom claim
      // This is also available via result.user.getIdTokenResult()
      // idTokenResult.claims.firebase.sign_in_attributes.
    })
    .catch((error) => {
      // Handle error.
    });

2)具有重定向

在这种情况下,您的代码应分为两部分。第一种sign-in方法,不使用任何Promise:

 firebase.auth().signInWithRedirect(provider);

然后,初始化“侦听器”,以在登录重定向后检索用户凭据:

// On return.
firebase.auth().getRedirectResult()
    .then((result) => {
      // User is signed in.
      // Identity provider data available in result.additionalUserInfo.profile,
      // or from the user's ID token obtained via result.user.getIdToken()
      // as an object in the firebase.sign_in_attributes custom claim
      // This is also available via result.user.getIdTokenResult()
      // idTokenResult.claims.firebase.sign_in_attributes.
    })
    .catch((error) => {
      // Handle error.
    });  

要添加到页面/应用程序的引导部分。

希望它会有所帮助。

© www.soinside.com 2019 - 2024. All rights reserved.