Google Apps脚本OAuth URI不匹配 [英] Google apps script oauth URI mismatch

查看:52
本文介绍了Google Apps脚本OAuth URI不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景:我正在使用Google Apps脚本创建Google表格的扩展程序.我要添加oAuth.

问题:oAuth需要授权的javascript来源.尝试使用google登录按钮登录时出现错误,提示uri重定向不匹配,并提供了script.googleusercontent.com uri.

我尝试过的方法:我添加了

黄色警告上的工具提示显示如下内容:"此自动生成的OAuth客户端ID是您的项目所必需的.不能修改."

如果您没有看到自动生成的客户ID,则有两个原因:

  1. 您没有将插件绑定到正确的项目中(有关更多信息,请参见云平台项目)
  2. 您尚未将项目绑定到附加组件.这不是强制性的,因为Google会自动使用您的加载项生成默认的+隐藏项目.

Background: I'm working within google apps script creating an extension for google sheets. I want to add oAuth.

The Issue: oAuth requires an authorized javascript origin. I get an error when attempting to login using the google sign in button saying uri redirect mismatch and gives a script.googleusercontent.com uri.

What I've tried: I add https://n-z2mpomgsi6mxzkdegvwhypizz4zxupdihnp6udy-0lu-script.googleusercontent.com from my redirect uri mismatch error to the list of authorized javascript origin uris in the developer console because stackoverflow said so. This gets oauth working fine and dandy.

The bigger issue: I go to access my program from another computer. oAuth doesn't work, I check the error and it's using a different script.googleusercontent.com uri in the error.

The Question: What uri can I add to authorized javascript origins to make google happy? (It does not accept wildcards ex. *googleusercontent.com).

解决方案

Google Apps Script handles automatically the OAuth authorization flow, so no need to register a JavaScript redirect URI or even a Client ID in your Google Cloud console, this will be fully managed by Google Apps Script.

Here's a great guide made by the Google on how Authorization Scopes work. But as reading it again, you're right that they don't mention the "authorized javascript origin URIs". That's because Google Apps Script generates one for the developer.

If you open your Google Cloud console, select the project your add-on is tied to and look at your API credentials, you should see within the OAuth 2.0 Client IDs something like the screenshot below:

The tooltip on the yellow warning says something like this: "This automatically generated OAuth client ID is required for your project. It can’t be modified."

If you don't see that auto-generated Client ID, there's two reason for that :

  1. You are not in the right project that your add-on is tied to (more on Cloud Platform Projects)
  2. You haven't tied a project to your add-on. Which is not mandatory per se, as Google will automatically generate a default + hidden project with your add-on.

这篇关于Google Apps脚本OAuth URI不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆