0

我目前无法解决的问题是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,因为今天我的主页可以使用 Identity Toolkit,但由于这个错误,我无法充分使用它。

4

3 回答 3

1

您需要创建两个页面。假设 url1 和 url2。

url1,您在其中包含您的登录按钮,方法是运行:

window.google.identitytoolkit.signInButton()

将 widgetUrl 设置为 url2

在您通过运行呈现小部件的 url2 中:

window.google.identitytoolkit.start()

将 signInSuccessUrl 设置为 url1

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

于 2015-08-01T06:33:56.127 回答
0

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

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

另外,删除

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

idps:[“谷歌”、“美国在线”、“微软”、“雅虎”、“Facebook”]、

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

显然只使用 signInOptions是这样做的方法。我在其他示例中阅读了 idps 而不是 signInOptions,并且我成功使用了 idps。

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

于 2015-08-02T22:51:31.897 回答
0

好吧,我刚刚遇到了同样的错误“错误代码:来自 IDP 的错误响应”。

如上面评论中所述,有两种可能性:

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

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

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

于 2015-10-01T21:20:08.343 回答