身份工具箱不工作-错误代码:IDP的错误响应

Identity Toolkit does not work - Error code: Bad response from IDP

本文关键字:IDP 错误 响应 错误代码 工具箱 工作 身份      更新时间:2023-09-26

我目前无法解决的问题是bad response from IDP,原因应该是缺乏mode=select,但我现在不知道mode=select必须实施的页面

事实上,我已经将代码添加到两个独立的页面中,第一个是index.php,它执行以下操作:

<script type="text/javascript" src="//www.gstatic.com/authtoolkit/js/gitkit.js"></script>
<script type="text/javascript">
var config = {
apiKey: 'AIzaSyAaMAfu7S2AITODrGJzVkIYBXlZR3FYhuQ',
signInSuccessUrl: 'http://www.lascuolacheverra.org/signin?mode=select', // i tried to add the `mode=select here`
signInOptions: ["google", "password"],
idps: ["Google", "AOL", "Microsoft", "Yahoo", "Facebook"],
oobActionUrl: '/',
siteName: 'La scuola che verrà A.P.S.',
    
    // Optional - function called after sign in completes and before
    // redirecting to signInSuccessUrl. Return false to disable
    // redirect.
    // callbacks: {
    //  signInSuccess: function(tokenString, accountInfo,
    //    opt_signInSuccessUrl) {
    //      return true;
    //    }
    // },
    
    // Optional - key for query parameter that overrides
    // signInSuccessUrl value (default: 'signInSuccessUrl')
    // queryParameterForSignInSuccessUrl: 'url'
    
    // Optional - URL of site ToS (linked and req. consent for signup)
     tosUrl: 'http://www.lascuolacheverra.org/privacypolicy.html',
    
    // Optional - URL of callback page (default: current url)
    // callbackUrl: 'http://example.com/callback',
    
    // Optional - Cookie name (default: gtoken)
    //            NOTE: Also needs to be added to config of the ‘page with
    //                  sign in button’. See above
    // cookieName: ‘example_cookie’,
    
    // Optional - UI configuration for accountchooser.com
    acUiConfig: {
     title: 'Sign in to lascuolacheverra.org',
     favicon: 'http://www.lascuolacheverra.org/favicon.ico',
     branding: 'http://www.lascuolacheverra.org/images/lascuolacheverra.jpg'
     },
    
    
    // Optional - Function to send ajax POST requests to your Recover URL
    //            Intended for CSRF protection, see Advanced Topics
    //      url - URL to send the POST request to
    //     data - Raw data to include as the body of the request
    //completed - Function to call with the object that you parse from
    //            the JSON response text. {} if no response
    /*ajaxSender: function(url, data, completed) {
     },
     */
};
// The HTTP POST body should be escaped by the server to prevent XSS
window.google.identitytoolkit.start(
                                    '#gitkitWidgetDiv', // accepts any CSS selector
                                    config,
                                    '{{ POST_BODY }}');
</script>
<!-- End modification -->


代码的第二部分位于另一个index.php中,执行以下操作:

<!DOCTYPE html>
<html>
<head>
<!-- Copy and paste here the "Sign-in button javascript" you downloaded from Developer Console as gitkit-signin-button.html -->
<script type="text/javascript" src="//www.gstatic.com/authtoolkit/js/gitkit.js"></script>
<link type=text/css rel=stylesheet href="//www.gstatic.com/authtoolkit/css/gitkit.css" />
<script type=text/javascript>
window.google.identitytoolkit.signInButton(
                                           '#navbar', // accepts any CSS selector
                                           {
                                           widgetUrl: "/widget",
                                           signOutUrl: "/",
                                           }
                                           );
</script>
<!-- End configuration -->
</head>
<body>
<!-- Include the sign in button widget with the matching 'navbar' id -->
<div id="navbar"></div>
<!-- End identity toolkit widget -->
<p>
{{ CONTENT }}
</p>
</body>
</html>

我想知道我如何才能正确使用mode=select,因为今天身份工具包可用于我的主页,但由于这个错误,我不能充分使用它。

您需要创建两个页面。比如url1和url2

url1,其中包含您的登录按钮运行:

window.google.identitytoolkit.signInButton ()

设置widgetUrl为url2

在url2中,您可以运行:

window.google.identitytoolkit.start ()

将signInSuccessUrl设置为url1

不要添加?mode=select到小部件url。当点击登录按钮时,它会自动将其附加到该url并重定向到那里。

signInSuccessUrl:'http://www.lascuolacheverra.org/signin?mode=select',//我尝试添加mode=select here

不应该指向/signin页。也许指向//signed-in

同时,删除

//signInOptions: ["google", "password"],//<——这显然掩盖了idps

国内流离失所者:("谷歌","美国在线"、"微软","雅虎","Facebook"],

我对此做了一些测试,如果我添加signInOptions,那么idps被忽略,您最终只能使用google和密码登录。

显然,只有使用signInOptions才能做到这一点。我在其他例子中读过idps而不是signInOptions,我成功地使用了idps。

Update我读错了代码。我认为'signin是显示小部件的页面,教程将其放在'widget下。我的错误,因为在我的项目中,我用'secure-sign-in代替'widget。因此,如果您的'signin页面不是'widget页面,那么您的代码已经OK了。在任何情况下,您都应该删除?mode=select,因为这只用于'widget,并且是由window.google.identitytoolkit.signInButton函数自动添加的。

我刚刚遇到了同样的错误"错误代码:来自IDP的不良响应。"

如上所述,有两种可能:

  1. 创建一个页面,只有一个登录按钮和另一个页面,前一个重定向到按钮点击
  2. "?mode=select"附加到url作为查询参数
  3. 在路由中重定向,例如

    app.get("/login", function(req, res) {
      res.redirect("/login?mode=select");        
    }
    

gitkit.js从浏览器中提取window.location.href .