rubicon-project / node-google-dfp

A service for integrating with Google DFP over NodeJS
ISC License
85 stars 34 forks source link

reuse access token to avoid some unnecessary round trips to google site #29

Open c0b opened 8 years ago

c0b commented 8 years ago

I have played with this library a few days it's working nicely while I noticed when my application need to talk to google for longer tasks, some part of this code is not caching and retrieving some resource again and again, for example google's oauth token has one hour validity by default, so within the hour we can reuse it, only need to refresh it until it's almost expiring, I'm doing some code changes locally to cache and it works better, can make a PR if it's welcome.

btw, google's library says refreshAccessToken is deprecated [2], I have switched to use getRequestMetadata; that is less code because google-auth-library handles token expiry and refresh itself pretty well

  1. https://github.com/ShinyAds/node-google-dfp/blob/master/lib/DfpUser.js#L120
  2. https://github.com/google/google-auth-library-nodejs/blob/master/lib/auth/oauth2client.js#L189-L195
mvhirsch commented 6 years ago

@c0b I just ran into the same problem. Could you please make a PR, so this could be merged into the library, too?

mvhirsch commented 6 years ago

Sadly the method getRequestMetadata isn't officially documented (heck, it's already the "preferred way" to authorize, because .authorize is already deprecated). For curious ones I'll just leave this here: https://github.com/google/google-auth-library-nodejs/issues/138