Context: GMail Add-on code with Library resource OAuth2 at version 29.
I have this code working (adjusted to show here):
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());
}
The callback function is like this:
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
}
The result of the stringified getToken()
call is a mess:
{"{\"access_token\":\"IqINbsrIchvc2bV27smQfAy5ldn6s6iJ9z9LPrUx/pJu+j9yJhb1MID/WBeVKrlvzvUrTPdcHdyhYz9CX0WcxLxbtCBU8wk6LdYQ8rRV5/XBE4XsU5Ik4wQNiItOimQf2f1V3VVuNSP/n50LCqVmQG0pNv/d5dUWnvq1OvSSJX9CvyY8RHioCsSn8pt/PTE4GYWy8R0/9wR2HbmIqjaDgg":"","granted_time":1534261033}
and the non-stringified output looks like
{granted_time=1.534261033E9, {"access_token":"IqINbsrIchvc2bV27smQfAy5ldn6s6iJ9z9LPrUx/pJu+j9yJhb1MID/WBeVKrlvzvUrTPdcHdyhYz9CX0WcxLxbtCBU8wk6LdYQ8rRV5/XBE4XsU5Ik4wQNiItOimQf2f1V3VVuNSP/n50LCqVmQG0pNv/d5dUWnvq1OvSSJX9CvyY8RHioCsSn8pt/PTE4GYWy8R0/9wR2HbmIqjaDgg=}
The remote authorization service is returning this JSON when it is called:
{
"access_token": "IqINbsrIchvc2bV27smQfP/PFXNLCvkfwNRFXoBX4QYH+WojfWNTi1GUdxUKWdaYPbblrAHQnAHgWRSb0iGn1pNIMQVwOYZb6KMY3eZCnxjHwC5lkotEmHdnLX5A2DihiAqaZy3w8ROc0pXafvl+7+E/meWWCnQdKXVEoc/7S3DD49yK0sNqTcA9AOdFrmxB4+SA3d56O6Zh6oOIx4NGug==",
"token_type": "bearer",
"expires_in": 3600
}
How do I get this to work correctly and give back the access token?