我正在尝试按照Google Sign-in的教程。我完全复制了谷歌的例子,但是当我按下登录按钮时,一个"无效的请求"报告错误。
我页面的网址是......
此页面的内容是......
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Title of the document</title>
<link rel="icon" href="favicon.ico" type="image/x-icon" />
<meta name="google-signin-scope" content="profile email">
<meta name="google-signin-client_id" content="230599269648-86peetl434op89ug41lg1vv8sjspfupp.apps.googleusercontent.com">
<script src="https://apis.google.com/js/platform.js" async defer></script>
<script>
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;
console.log("ID Token: " + id_token);
};
</script>
</head>
<body>
Content of the document......
<div class="g-signin2" data-onsuccess="onSignIn" data-theme="dark"></div>
<a href="#" onclick="signOut();">Sign out</a>
<script>
function signOut() {
var auth2 = gapi.auth2.getAuthInstance();
auth2.signOut().then(function () {
console.log('User signed out.');
});
}
</script>
</body>
</html>
网络应用程序已在Google Developer's Console中正确注册。这是以json格式下载的注册......
{
"web": {
"client_id": "230599269648-86peetl434op89ug41lg1vv8sjspfupp.apps.googleusercontent.com",
"project_id": "test-federated-login-196400",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://accounts.google.com/o/oauth2/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_secret": (redacted),
"javascript_origins": [
"https://s3-ap-southeast-2.amazonaws.com"
]
}
}
当用户按下登录按钮时,弹出对话框会报告带有文本的错误...
400. That’s an error.
Error: invalid_request
Permission denied to generate login hint for target domain.
...包含请求详情......
redirect_uri=storagerelay://https/s3-ap-southeast-2.amazonaws.com?id=auth370793
response_type=permission id_token
scope=email profile openid
openid.realm=
client_id=230599269648-86peetl434op89ug41lg1vv8sjspfupp.apps.googleusercontent.com
ss_domain=https://s3-ap-southeast-2.amazonaws.com
fetch_basic_profile=true
gsiwebsdk=2
如何在网页上使用Google登录这个基本示例?
答案 0 :(得分:0)
我有一个解决方法。我无法解释为什么它有效,OP解决方案没有。
AWS桶对象有两种不同的URL格式:
我使用Google的网站管理员中心来声明所有权并验证两个域的所有权:
虽然我当然不能声称https://s3-ap-southeast-2.amazonaws.com
第一种形式的URL通常用于API。第二种用于浏览器(尽管在第二种形式中,只允许使用http,而不是https)。
然后我修改了javascript起源以添加第二种形式...
{ “web”:{ “client_id”:“230599269648-86peetl434op89ug41lg1vv8sjspfupp.apps.googleusercontent.com”, “project_id”:“test-federated-login-196400”, “auth_uri”:“https://accounts.google.com/o/oauth2/auth”, “token_uri”:“https://accounts.google.com/o/oauth2/token”, “auth_provider_x509_cert_url”:“https://www.googleapis.com/oauth2/v1/certs”, “client_secret”:(编辑), “javascript_origins”:[ “https://s3-ap-southeast-2.amazonaws.com”, “http://sbd-aws-sdk-delphi-22.s3-website-ap-southeast-2.amazonaws.com” ] } }
...然后通过第二种形式在浏览器中寻址页面...
......然后我可以登录。
我无法退出。 sign0out按钮引发了javascript错误,但这是另一天的另一个问题。
在亚马逊AWS托管存储桶上实施Google登录时......