In my app I have multiple users who I have tokens for, and a function to retrieve their google plus profile. In this function should I be re-instantiating an Oauth2Client so that when I call setCredentials() it doesn't change the credentials of a global client? Something like this
function getProfile(token) {
const oauth2Client = new OAuth2(
'id',
'secret,
'https://redirect.url'
);
oauth2Client.setCredentials(token);
gmail.users.getProfile({userId: '', auth:oauth2Client})...
OR is it smart to use a global oauth client, and just call setCredentials() every time inside the function. Hopefully credentials aren't mixed up between a-sync calls?
const oauth2Client = new OAuth2(
'id',
'secret,
'https://redirect.url'
);
function getProfile(token) {
oauth2Client.setCredentials(token);
gmail.users.getProfile({userId: '', auth:oauth2Client})...
Greetings! I would advise creating a new OAuth2Client for each set of users. There's a fair bit of caching and such that happens inside of the client objects, and I wouldn't trust data not to get mixed up. Hope this helps!
Most helpful comment
Greetings! I would advise creating a new OAuth2Client for each set of users. There's a fair bit of caching and such that happens inside of the client objects, and I wouldn't trust data not to get mixed up. Hope this helps!