google-apps-script - 每台计算机上同一 Web 应用程序的不同 JavaScript 源导致错误:redirect_uri_mismatch
问题描述
我使用 Google 应用程序脚本发布了一个带有 Google 登录的 WebApp。每次您在另一台计算机上登录您的 google 帐户以访问此网络应用程序时,都会出现错误:“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 的位置。如果 iframe 以外0lu
的其他内容,我们将其替换为0lu
推荐阅读
- qt - 通过 VPN 开/关更改地址,Qt 网络失败。替代?
- php - amazon payfort 捕获操作错误:“不允许操作:捕获”
- reactjs - 在 React 中的类组件内声明函数
- swift - 如何在swift 4中记录特定的uiview
- reactjs - 如何使用反应钩子将我的类和 render() 转换为功能组件?
- c# - .Net Core WebAPI:使用不同的 json 序列化器选项来反序列化同一控制器中的请求体
- c# - 如何在实体框架中调用带有联接的存储过程?
- laravel - 如何获取 Vue3 Object 单个元素?
- scala - `F[_ <: A] <: B` 在类型级别和 `f: A => B` 在值级别之间的类比
- python - 如何在 Ubuntu 20.04 中运行手动运行但不使用 CRON 的 Python Cron 作业?