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']'会在那里,但这取决于你使用验证。一旦通过验证,您可以在会话中设置事物。 –