使用具有以下配置的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
格式的重定向发布页面:
这继而使CICP渲染并返回带有已设置脚本的页面
var POST_BODY=""------WebKitFormBoundary9bn7AOpnZiIRk9qZ\r\nContent....."
即而不是解析表单主体并提取SAMLResponse字段,而是将整个Request.body重播到脚本中,然后调用fireauth.oauthhelper.widget.initialize();
这显然失败,因为该往返然后尝试将整个响应正文作为查询字符串发布到/__/auth/handler
端点。
我怀疑此链中缺少一个简单的配置项,因为所有流程对我来说都是正常的,直到多部分表单数据被推入POST_BODY,然后阻止将SAML令牌转换成OAuth令牌。
此(已编辑的)设置中哪个配置项不正确,以及用其替换的值的正确推导是什么?
[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.
});
要添加到页面/应用程序的引导部分。
希望它会有所帮助。