1
我目前正在使用Google身份登錄代碼在我們的網站上設置自定義登錄。我從這裏跟隨了文檔。 https://developers.google.com/identity/sign-in/web/Google身份登錄後用戶登錄後重定向
我已登錄並且按鈕全部正常工作。我的問題是,我能夠在成功登錄後重定向用戶嗎?我曾嘗試在API管理器中使用「授權重定向URI」,但沒有運氣。
對此的任何幫助或指導將是偉大的。
我目前正在使用Google身份登錄代碼在我們的網站上設置自定義登錄。我從這裏跟隨了文檔。 https://developers.google.com/identity/sign-in/web/Google身份登錄後用戶登錄後重定向
我已登錄並且按鈕全部正常工作。我的問題是,我能夠在成功登錄後重定向用戶嗎?我曾嘗試在API管理器中使用「授權重定向URI」,但沒有運氣。
對此的任何幫助或指導將是偉大的。
你需要在回調函數中做你自己的重定向。想象一下documentation here中的代碼。你需要做的是延長它像這樣:
function onSignIn(googleUser) {
// Useful data for your client-side scripts:
var profile = googleUser.getBasicProfile();
console.log("ID: " + profile.getId()); // Don't send this directly to your server!
console.log('Full Name: ' + profile.getName());
console.log('Given Name: ' + profile.getGivenName());
console.log('Family Name: ' + profile.getFamilyName());
console.log("Image URL: " + profile.getImageUrl());
console.log("Email: " + profile.getEmail());
// The ID token you need to pass to your backend:
var id_token = googleUser.getAuthResponse().id_token;
postAJAX('/server/sign-in', {id_token: id_token})
.then(function(user) {
// The user is now signed in on the server too
// and the user should now have a session cookie
// for the whole site.
document.location.href = '/dashboard/' + user.username
})
};
我假設'/服務器/籤in'會把''在$ _ POST [ 'id_token']了' $ _SESSION'超全球。那是對的嗎?你是否也在會話中切換某種授權布爾值? –
另外,我想你可能會在你的'postAJAX'函數調用(從底部開始的第三行)末尾丟失一個分號。 –
服務器端部分由您決定。 '$ _POST ['id_token']'會在那裏,但這取決於你使用驗證。一旦通過驗證,您可以在會話中設置事物。 –