【发布时间】:2019-12-01 23:57:58
【问题描述】:
我正在尝试在客户端使用 Google 平台库和在后端使用 google-auth-library 对用户进行 o 身份验证。使用以下代码,因为我正在关注official tutorial
<meta name="google-signin-client_id"
content="myuserid.apps.googleusercontent.com">
<meta name="google-signin-scope" content="profile email">
<script src="https://apis.google.com/js/platform.js" async defer></script>
<script>
function onSignIn(googleUser) {
var profile = googleUser.getBasicProfile();
var id_token = googleUser.getAuthResponse().id_token;
var xhr = new XMLHttpRequest();
xhr.open('POST', 'http://mysubdomain.openshiftapps.com/oauth/google/redirect');
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.onload = function() {
console.log('Signed in as: ' + xhr.responseText);
};
xhr.send('idtoken=' + id_token);
}
</script>
我没有看到客户端发出任何发布请求。
使用 Chrome 或 Internet Explorer 调试工具,只显示加载资源的请求,platform.js 其中。
ps:myuserid 和 mysubdomain 被它们的值替换。
【问题讨论】:
-
控制台没有错误?
-
你有原因,它显示类似:“cookies are not enabled in current environment.”错误:“idpiframe_initialization_failed”但我一开始没有注意。
标签: javascript http request xmlhttprequest