javascript - Identity Toolkit 无法工作 - 错误代码 : Bad response from IDP

标签 javascript html google-identity-toolkit

我目前无法解决的问题是来自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,但我无法充分使用它,因为这个错误。

最佳答案

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

url1,您可以通过运行以下命令来包含登录按钮:

window.google.identitytoolkit.signInButton()

将 widgetUrl 设置为 url2

在 url2 中,通过运行以下命令来呈现小部件:

window.google.identitytoolkit.start()

将signInSuccessUrl设置为url1

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

关于javascript - Identity Toolkit 无法工作 - 错误代码 : Bad response from IDP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31714765/

相关文章:

javascript - 自动完成显示 [object object] 列表项而不是值

javascript - 自动触发 lightbox_me 关闭

javascript - ng-bind-html 在我的上下文中不起作用

javascript - Css 在每一行的底部放置一个完整的行,带有 Angular ng 重复

facebook - 您可以扩展 Google Identity Toolkit 以包括 facebook/twitter/etc 吗?

javascript - 如何在 javascript 中获取 URL 参数的值?

java - StyledEditorKit 文本对齐无法正常工作

HTML5/CSS3 如何强制文本需要一定的宽度才能渲染

javascript - 如何通过 Google Identity Toolkit 修改登录按钮? ( Node .js)

ios - Swift 桥接头文件不适用于 use_frameworks