Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unreliable with setCache(CacheService.getUserCache()) #332

Open
andreask1 opened this issue Oct 20, 2021 · 0 comments
Open

Unreliable with setCache(CacheService.getUserCache()) #332

andreask1 opened this issue Oct 20, 2021 · 0 comments

Comments

@andreask1
Copy link

andreask1 commented Oct 20, 2021

Using a cache seems to make it unreliable to get tokens in at least the following situation:

  • Two different services created
  • Services used within a library
  • Library embedded in an outer script
  • Library function called in the outer script with doPost

The following error is thrown randomly for one of the services. "Error: Access not granted or expired.
Service_.getAccessToken (Service)". When service1 is working and I re-authenticate service2, then service1 stops working. However, when I remove setCache from both services, everything works reliable.

The following entry point in the example below does not work reliably when using setCache:

  • doPost(e) in outer script

All the other ones work reliably:

  • manualCall() in outer script
  • doPost(e) in Libary when used as standalone script
  • manualCall() in Libary when used as standalone script

For me it's not a big deal to not use the cache but this might help fixing the root cause or prevent others from hours of debugging when running into an "Access not granted or expired" error.

function doPost(e) {
  Library.webhook();
}
function manualCall() {
  Library.webhook();
}
function authCallback1(request) {
  return Library.authCallback1(request);
}
function authCallback2(request) {
  return Library.authCallback2(request);
}

Library: {
  function doPost(e) {
    webhook();
  }
  function manualCall() {
    webhook();
  }
  function webhook() {
    ...
    let service1 = OAuth2.createService('service1')
        .setCallbackFunction('authCallback1')
        .setPropertyStore(PropertiesService.getUserProperties())
        .setCache(CacheService.getUserCache())
    ...
    service1.getAccessToken(); //Random error
    ...
    let service2 = OAuth2.createService('service2')
        .setCallbackFunction('authCallback2')
        .setPropertyStore(PropertiesService.getUserProperties())
        .setCache(CacheService.getUserCache())
    ...
    service2.getAccessToken(); //Random error
    ...
  }
  function authCallback1(request) {
    ...
  }
  function authCallback2(request) {
    ...
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant