我目前正在使用Google的身份登录代码在我们的网站上设置自定义登录。我从这里开始遵循文档。 https://developers.google.com/identity/sign-in/web/
我已登录,按钮全部正常工作。我的问题是,我是否能够在用户成功登录后重定向?我曾尝试在API管理器中使用“授权重定向URI”,但没有运气。
对此的任何帮助或指导都会很棒。
答案 0 :(得分:1)
您需要在回调函数中进行自己的重定向。想象一下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
})
};