apps-script-oauth2 icon indicating copy to clipboard operation
apps-script-oauth2 copied to clipboard

Ability to change the expire_in value?

Open MrCaspan opened this issue 4 years ago • 3 comments

So I am having an issue where I get a bearer token that is impersonating a user but then the user changed their password which invalidates the bearer token. So instead of script erroring out for an hour I would like to set the bearer token to live for only 30 seconds. basically a new token would be requested at each run. I could change my script to not cache them but I figure it would be better then have 15 active tokens laying around while an old one is still active is to expire them and just get a new one

MrCaspan avatar Oct 19 '21 16:10 MrCaspan

NM after walking the code I found this https://github.com/googleworkspace/apps-script-oauth2/blob/master/dist/OAuth2.gs#L400 You guys should add this to the documentation as this is quite important to know

MrCaspan avatar Oct 19 '21 16:10 MrCaspan

Actually this is not working I will set this to 2 and my expires_in is still set to 3599. Any help would be appreciated! BTW i am using version 41 of this in my Google App Script

MrCaspan avatar Oct 19 '21 17:10 MrCaspan

Here is the code I am using to create my service

    return OAuth2.createService(name)
      .setSubject(userToImpersonate)
      .setTokenUrl('https://accounts.google.com/o/oauth2/token')
      .setPrivateKey(serviceAccount.private_key)
      .setIssuer(serviceAccount.client_email)
      .setPropertyStore(PropertiesService.getScriptProperties())
      .setScope(scopes)
      .setLock(LockService.getScriptLock())
      .setExpirationMinutes(2);

MrCaspan avatar Oct 19 '21 17:10 MrCaspan