我正在尝试使用Google脚本创建一个新的Gmail附加程序,并尝试访问第三方的、非Google。为此,我使用O-Auth2.0隐式格兰特-类型进行身份验证。
这就是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')作为隐式格兰特类型。
发布于 2018-10-31 10:42:43
该库目前不支持隐式授权。Google AppScript支持服务器端流。因此,我设置了response_type = code,这是工作授权服务,如下所示:
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', 'code')
.setParam('response_mode', 'query')
.setParam('state', getStateToken('authCallback')) // function to generate the state token on the fly
.setPropertyStore(PropertiesService.getUserProperties());
}它首先在内部调用autorizatiionBaseUrl并接收授权代码。使用此授权代码,它再次向TokenUrl发出post请求,以获取auth_token、refresh_token和其他详细信息。谢谢。:)
发布于 2018-10-06 03:29:18
根据您在apps-script-oauth2 GitHub回购中的问题,您在Apps脚本中(使用该库)中的OAuth的特定实现不支持隐式格兰特。考虑到Apps脚本在服务器上执行(而不是在客户机中执行,而隐式授予是最有用的),那么您使用的库也不太可能被扩展来支持它。
https://stackoverflow.com/questions/52671507
复制相似问题