簡體   English   中英

身份工具包不起作用-錯誤代碼:來自IDP的錯誤響應

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

我目前無法解決的問題是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à APS', // 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並在那里重定向。

signInSuccessUrl:' http : //www.lascuolacheverra.org/signin ? mode=select here ',//我嘗試在mode=select here添加mode=select here

這不應指向/signin頁面。 也許將其指向//signed-in

另外,移除

// signInOptions:[“ google”,“ password”],// <-這顯然掩蓋了idps

idps:[“ Google”,“ AOL”,“ Microsoft”,“ Yahoo”,“ Facebook”],

我對此進行了一些測試,如果我添加signInOptions,則idps被忽略,您最終只能使用google和密碼登錄。

顯然,僅使用signInOptions 即可 在其他示例中,我已經閱讀了idps而不是signInOptions,並且成功使用了idps。

更新我誤讀了一點代碼。 我以為\\signin是顯示小部件的頁面,教程將其放置在\\widget 我的錯誤是因為在我的項目中,我將\\widget替換為\\secure-sign-in 因此,如果您的\\signin頁面不是\\widget頁面,則您的代碼已經可以了。 而且無論如何,您都應該刪除?mode=select因為它僅用於\\widget並且是由window.google.identitytoolkit.signInButton函數自動添加的。

好吧,我只是遇到了同樣的錯誤“錯誤代碼:IDP的響應錯誤”。

如上面的評論所述,有兩種可能性:

  1. 創建一個僅具有SignIn-Button的頁面,並在單擊按鈕時將前一個重定向到的頁面
  2. "?mode=select"附加到URL作為查詢參數
  3. 重定向您的路線,例如

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

gitkit.js從瀏覽器window.location.href 提取它

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM