googleworkspace / apps-script-oauth2

An OAuth2 library for Google Apps Script.
https://developers.google.com/apps-script/
Apache License 2.0
1.56k stars 429 forks source link

IsAuthValid() refresh occurs when Oauth Popup window is opened, not when Oauth popup window is closed (and oauth process finishes) #440

Closed avianion closed 1 year ago

avianion commented 1 year ago

My issue is, upon clicking "Authorize", and the popup window appearing, the "refresh" that checks IsAuthValid() occurs.

This is obviously not ideal, as this refresh should only occur when the window is closed, and the oauth is completed.

It does not occur when the window is closed after the authCallback, but occurs at the beginning, the second the content in the window loads.

Here is the code for creating the OauthService. I believe everything is fairly normal here.

var service = OAuth2.createService(SERVICE_NAME) .setAuthorizationBaseUrl(AUTHORIZATION_BASE_URL) .setTokenUrl(TOKEN_URL) .setClientId(scriptProps.getProperty(CLIENT_ID_PROPERTY_NAME)) .setClientSecret(scriptProps.getProperty(CLIENT_SECRET_PROPERTY_NAME)) .setPropertyStore(PropertiesService.getUserProperties()) .setCallbackFunction("authCallback") .setTokenHeaders({ Authorization:Basic ${bearer_cred}, "Cache-Control": "no-cache", "Content-Type": "application/x-www-form-urlencoded", }) .setTokenPayloadHandler(addParamsToTokenPayload);

image

here is what I mean by the "refresh" that checks if IsAuthValid() -> which will obviously return false, as the window has literally just been opened and the user has had no chance to finish the oauth flow.

image