verbb / consume

A Craft CMS plugin to create HTTP requests in your Twig templates to consume JSON, XML or CSV content.
Other
4 stars 1 forks source link

Google Service account expires after 1 hour #4

Closed scandella closed 8 months ago

scandella commented 8 months ago

Describe the bug

I am able to work with Google Drive object using Consume, but after 1 hour, it errors out with exception: "The remote server returned an error: (401) Unauthorized." It seems that, by setting "access_type" to "offline", when a user consents to offline access a refresh token is returned that can be swapped (along with the client secret) at any time for an access token. Is this a settings that you can implement? Otherwise, connecting to Google Drive via Consume is not very helpful. Best

Steps to reproduce

  1. Connect to Google Service
  2. Wait an hour, Consume still flag the connexion as "connected" but every query failed with a 401 error
  3. Disconnect then reconnect the Consume client: the connexion will last another 1 hour

Craft CMS version

Craft 4.5.11.1

Plugin version

1.0.4

Multi-site?

No

Additional context

No response

engram-design commented 8 months ago

Correct - we should be sending through the accessType = 'offline' option to the authorization URL.

Fixed for the next release. To get this early, run composer require verbb/consume:"dev-craft-4 as 1.0.4"

You will need to disconnect and reconnect.

scandella commented 8 months ago

Thanks for your answer. I've installed the beta version ('dev-craft-4'). I can see the options['access_type'] = 'offline'; in our Google.php file. I've created a fresh Google client, but I see no change with the token expiration: delay is still one hour. In the "auth_oauth_tokens" table, the "refreshToken' entry is still empty.

Best.

engram-design commented 8 months ago

Ah, looks like you also need to include $options['prompt'] = 'consent' as well. This tripped me up as this was shown the first time I connected, but subsequent connects didn't show the prompt, and that doesn't seem to allow a refresh token to be generated.

Fixed for the next release. To get this early, run composer require verbb/consume:"dev-craft-4 as 1.0.4"

scandella commented 8 months ago

Many thanks. It works now!