【发布时间】:2019-03-11 07:24:54
【问题描述】:
我正在尝试使用 Google Apps 脚本创建新的 Gmail 插件并尝试访问第三方非 Google API。为此,我使用 O-Auth 2.0 Implicit Grant-Type 进行身份验证。
这就是AuthService 的样子:
function getOAuthService() {
return OAuth2.createService('Podio O-Auth')
.setAuthorizationBaseUrl('Base Url')
.setTokenUrl('Token Url')
.setClientId('clientId')
.setClientSecret('clientSecret')
.setParam('redirect_uri', 'https://script.google.com/macros/d/' + scriptID + '/usercallback')
.setScope('GLOBAL')
.setCallbackFunction('authCallback')
.setCache(CacheService.getUserCache())
.setParam('response_type', 'token')
.setParam('response_mode', 'query')
.setParam('state', getStateToken('authCallback')) // function to generate the state token on the fly
.setPropertyStore(PropertiesService.getUserProperties());
}
脚本正确生成了一个包含我的redirect_uri的 URL
Auth 获取请求,生成令牌,并将我重定向到 scripts.google.com 域。
点击scripts.google.com 后,我会被重定向到包含我的自定义域的 URL,例如
https://script.google.com/a/macros/[custom-domain]/d/[script-id]/usercallback#access_token=[token]&expires_in=7200&token_type=Bearer&state=[state]&id_token=[token]
导致此错误的原因:
因为 url 被# 分割。如果我将# 替换为?,那么它会按预期工作。
谁能告诉我如何解决这个问题?如果没有,那么我是否必须为此目的授权代码授予流程?
注意:我已将 setParam('response_type', 'token') 用于隐式授予类型
【问题讨论】:
-
如果您向您正在使用的
OAuth2库的作者咨询,您可能会获得一些额外的信息。有人会认为,如果 Apps Script 不支持 Implicit Grant,那么为 Apps Script 编写的OAuth2库同样不会启用 Implicit Grant。 -
@tehhowch OP 确实并且已经收到了作者的答复。他可能正在等待其他答案。
标签: authentication google-apps-script oauth-2.0 google-oauth gmail-addons