Openid 获得;王国没有';与重定向uri/源不匹配。错误代码:2“;
当我尝试登录时,登录窗口会按预期弹出,但它会给我这个错误Openid 获得;王国没有';与重定向uri/源不匹配。错误代码:2“;,openid,google-api-java-client,openid-connect,google-openid,Openid,Google Api Java Client,Openid Connect,Google Openid,当我尝试登录时,登录窗口会按预期弹出,但它会给我这个错误 Error: invalid_request Realm didn't match redirect_uri/origin. Error code: 2 Request Details: openid.realm=localhost:8080/oauth2callback scope=email profile openid https://www.googleapis.com/auth/userinfo.email response
Error: invalid_request
Realm didn't match redirect_uri/origin. Error code: 2
Request Details:
openid.realm=localhost:8080/oauth2callback
scope=email profile openid https://www.googleapis.com/auth/userinfo.email
response_type=permission
redirect_uri=storagerelay://http/localhost:8080?id=auth435566
ss_domain=http://localhost:8080
client_id=SOME_STRING_ID.apps.googleusercontent.com
fetch_basic_profile=true
我通读了,从我对它的理解来看,属性openid.realm
,应该与我的一个重定向uri相同
以下是我在“凭据”部分中从开发人员控制台获得的“授权重定向URI”:
https://myapp-1234.appspot.com/oauth2callback
http://myapp-1234.appspot.com/oauth2callback
http://localhost:8080/oauth2callback
我将openid.realm
设置为localhost:8080/oauth2callback
,因为目前我只测试我的应用程序,但我在部署中尝试了其他应用程序,仍然得到了相同的结果,但错误代码不同
这里是调用signIn()
方法的地方:
var authConfig = {
client_id: 'SOME_STRING_ID.apps.googleusercontent.com',
cookie_policy: 'single_host_origin',
scope: 'https://www.googleapis.com/auth/userinfo.email profile',
openid_realm: 'localhost:8080/oauth2callback'
}
window.handleGoogleClientLoad = function () {
gapi.client.load('myapp_endpoints', 'v1', null, '//' + window.location.host + '/_ah/api');
console.log('API LOADED');
}
//=====================================================================================
function authorizeUser() {
gapi.load('auth2', function() {
gapi.auth2.init(authConfig)
.then(function() {
var auth2 = gapi.auth2.getAuthInstance();
var user = auth2.signIn();
console.log(user);
});
});
}
module.exports = {
login: authorizeUser
}
这里是index.html
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<title>My App</title>
</head>
<body>
<div id="root"></div>
<script src="lib/vendors.js"></script>
<script src="build/bundle.js"></script>
</body>
我的应用程序
问题是我使用了错误的Google API库。我在用你从图书馆得到的。然后我导入了模块
import GoogleApis from 'googleapis'
我想做的是使用可以从他们自己的网站下载的库。这很方便。您只需将下面的代码行添加到index.html
<script src="https://apis.google.com/js/platform.js" async defer></script>
openid.realm=response\u type=permission 身份证 重定向_uri=storagerelay://https/www.zillow.com?id=auth807591 ss_域=https://www.zillow.com client_id=238648973530.apps.googleusercontent.com 获取基本配置文件=true gsiwebsdk= 访问类型=在线
范围=https://www.googleapis.com/auth/userinfo.email openid您解决过这个问题吗?我遇到了同样的问题。@Jason Malcolm对延迟回复表示歉意。但我刚刚为这个问题添加了一个答案,请查看。希望它对你有用。你能给你的答案加上一些解释吗。
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<title>Welcome to MyApp</title>
</head>
<body>
<div id="root"></div>
<script src="lib/vendors.js"></script>
<script src="build/bundle.js"></script>
<script src="https://apis.google.com/js/platform.js?onload=init" async defer></script>
<!-- init is the function that will get invoked when the page loads. -->
</body>
const authConfig = {
client_id: 'my_app.apps.googleusercontent.com',
cookie_policy: 'single_host_origin',
scope: 'https://www.googleapis.com/auth/userinfo.email profile',
fetch_basic_profile: true
}
window.init = function() {
gapi.load('auth2', function() {
var auth2 = gapi.auth2.init(authConfig);
auth2.signIn().then(function() {
if(auth2.isSignedIn.get()) {
var profile = auth2.currentUser.get().getBasicProfile();
console.log('ID: ' + profile.getId());
console.log('Full Name: ' + profile.getName());
console.log('Email: ' + profile.getEmail());
}
});
});
}