OAuth2 Google脚本库-错误的令牌

时间:2018-08-14 15:45:19

标签: google-oauth2 gmail-addons

上下文:版本29的带有库资源OAuth2的GMail附加代码。

我正在执行此代码(调整为在此处显示):

function getOAuthService() {
    return OAuth2.createService('myName')
        .setAuthorizationBaseUrl(baseUrl)
        .setTokenUrl(tokenUrl)
        .setTokenFormat('application/x-www-form-urlencoded')
        .setClientId('myId')
        .setClientSecret(mySecret)
        .setScope('myScope') // arbitrary text
        .setCallbackFunction('authCallback')
        .setCache(CacheService.getUserCache())
        .setPropertyStore(PropertiesService.getUserProperties());
}

回调函数如下:

function authCallback(request) {
    var service = getOAuthService();
    var authorized = service.handleCallback(request);
    console.log(authorized); // -->   true
    console.log(service.getAccessToken()); // --> undefined
    console.log(JSON.stringify(service.getToken())); // --> see below
    console.log(service.getToken()); // --> see below
}   

getToken()字符串化调用的结果是一团糟:

  

{ “{\” 的access_token \ “:\” IqINbsrIchvc2bV27smQfAy5ldn6s6iJ9z9LPrUx / PJU + j9yJhb1MID / WBeVKrlvzvUrTPdcHdyhYz9CX0WcxLxbtCBU8wk6LdYQ8rRV5 / XBE4XsU5Ik4wQNiItOimQf2f1V3VVuNSP / n50LCqVmQG0pNv / d5dUWnvq1OvSSJX9CvyY8RHioCsSn8pt / PTE4GYWy8R0 / 9wR2HbmIqjaDgg “:””, “granted_time”:1534261033}

非字符串化的输出看起来像

  

{granted_time = 1.534261033E9,{ “ACCESS_TOKEN”:“IqINbsrIchvc2bV27smQfAy5ldn6s6iJ9z9LPrUx / PJU + j9yJhb1MID / WBeVKrlvzvUrTPdcHdyhYz9CX0WcxLxbtCBU8wk6LdYQ8rRV5 / XBE4XsU5Ik4wQNiItOimQf2f1V3VVuNSP / n50LCqVmQG0pNv / d5dUWnvq1OvSSJX9CvyY8RHioCsSn8pt / PTE4GYWy8R0 / 9wR2HbmIqjaDgg =}

远程授权服务在调用时返回此JSON:

{
  "access_token": "IqINbsrIchvc2bV27smQfP/PFXNLCvkfwNRFXoBX4QYH+WojfWNTi1GUdxUKWdaYPbblrAHQnAHgWRSb0iGn1pNIMQVwOYZb6KMY3eZCnxjHwC5lkotEmHdnLX5A2DihiAqaZy3w8ROc0pXafvl+7+E/meWWCnQdKXVEoc/7S3DD49yK0sNqTcA9AOdFrmxB4+SA3d56O6Zh6oOIx4NGug==",
  "token_type": "bearer",
  "expires_in": 3600
}

如何使它正常工作并退回访问令牌?

0 个答案:

没有答案