我已经使用 Google 应用程序脚本发布了一个带有 Google 登录的 WebApp。每次您在另一台计算机上登录您的谷歌帐户访问此网络应用程序时,都会出现错误:“redirect_uri_mismatch”。
我看到在每台登录到 google 帐户的计算机上,已发布的网络应用程序在请求链接中具有不同的 javaScript 源,我已将此链接添加到 Google 开发人员控制台上的授权 JavaScript 源中,以便这台计算机登录以及使 Google签到工作。
我希望我的 console.developers.google.com 只有一个授权的 JavaScript 来源(链接应用程序脚本)。我希望所有用户访问和登录时不会出现错误“redirect_uri_mismatch”
上千用户不方便,如何改进?
HTML 代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="google-signin-client_id" content="1xxxxxxxxxx-xxxxxxxxi87eht.apps.googleusercontent.com">
<title>Oauth2 web</title>
<!-- Google library -->
<script src="https://apis.google.com/js/platform.js" async defer></script>
<!-- Jquery library to print the information easier -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
<!-- Bootstrap library for the button style-->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
</head>
<body>
<div id="profileinfo">
</div>
<div class="g-signin2" data-onsuccess="onSignIn"></div>
<script>
function onSignIn(googleUser) {
var profile = googleUser.getBasicProfile();
console.log('ID: ' + profile.getId()); // Do not send to your backend! Use an ID token instead.
console.log('Name: ' + profile.getName());
console.log('Image URL: ' + profile.getImageUrl());
console.log('Email: ' + profile.getEmail()); // This is null if the 'email' scope is not present.
$("#profileinfo").append("<h2>Sup " + profile.getName() + ", welcome home my friend</h2>");
$("#profileinfo").append("<img style='width:250px;height:250px' src='" + profile.getImageUrl() + "'><br><br>");
$("#profileinfo").append("<p>Your email is: " + profile.getEmail() + "</p>");
}
</script>
<button type="button" class="btn btn-danger" onclick="signOut();">Sign out</button>
<script>
function signOut() {
var auth2 = gapi.auth2.getAuthInstance();
auth2.signOut().then(function () {
console.log('User signed out.');
$("#profileinfo").empty();
$("#profileinfo").append("<h2>Goodbye old friend</h2>");
});
}
</script>
</body>
</html>
最佳答案
这可能行不通,但您可以使用 index.html 中的脚本将默认值设置为 0:
<script>
if(!/-0lu/.test(location.href)){
location.href = location.href.toString().replace(/-\d+lu/,'-0lu');
}
</script>
您的网络应用 script.google.com
有一个沙盒 iframe *[DIGIT]lu-script.googleusercontent.com
。我们只是尝试使用正则表达式更改此 iframe 的位置。如果不是 0lu
作为 iframe 存在,我们将其替换为 0lu
关于google-apps-script - 每台计算机上同一 Web 应用程序的不同 JavaScript 来源导致错误 : redirect_uri_mismatch,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56862586/