janvda / node-red-contrib-google-photos

Node-RED node for Google APIs using OAuth2.
MIT License
0 stars 0 forks source link

Getting `Request had invalid authentication credentials.` #2

Closed janvda closed 4 years ago

janvda commented 4 years ago

More precisely the following error is raised in node-red editor:

StatusCodeError: 401 - {"error":{"code":401,"message":"Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.","status":"UNAUTHENTICATED"}}

janvda commented 4 years ago

Interesting links:

janvda commented 4 years ago

Further investigation revealed that the access token expires after 1 hour. google.auth.OAuth2 is automatically retrieving new access token using the refresh token but the new access token is not used by Photos().

For this googlephotos library will be extended with a new method to update the access token => see https://github.com/roopakv/google-photos/issues/19

janvda commented 4 years ago

when the acces_token expires, it is also not automatically refreshed or more precisely the method oauth2Client.on('tokens', ... is never triggered.

So, it is not clear how I can "force" an automatic refresh of the access token. See also https://github.com/googleapis/google-api-nodejs-client/pull/1177

See also https://github.com/googleapis/google-api-nodejs-client/issues/1256

janvda commented 4 years ago

This has been fixed by commit 43d3387b2186376eaec282c66073a1a1d9cd4df3 and earlier commits.

So it will during startup use the refresh token to request a new access token.