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

Adding a scope to Google OAuth Connection causes array_merge error #3

Closed carterheron closed 10 months ago

carterheron commented 1 year ago

Describe the bug

I setup a Google OAuth Connection following the guide listed here. If I omit the OAuth scopes for this provider I am able to successfully connect, however, for this application, I need the token to be assigned with specific scope privileges and as soon as I add a scope in, (for example https://www.googleapis.com/auth/analytics.readonly) It refuses to connect. I added a debug statement in the source code and found that this seems to be caused by this error:

“array_merge(): Argument #2 must be of type array, string given” /var/www/html/vendor/verbb/auth/src/clients/google/provider/Google.php:75.

Google

Turns out $options['scope'] always returns a string, even if additional scopes are added within the control panel (thus always causing the array_merge error).

Steps to reproduce

  1. Setup a craft 4 build (4.4.15)
  2. Install Consume Plugin
  3. Follow instructions to create a Google OAuth Client here
  4. Add an additional scope
  5. Test connection

Craft CMS version

4.4.15

Plugin version

1.0.3

Multi-site?

No

Additional context

Checking my database, the object settings column contains the object : {"proxyRedirect":"$DEV_MODE","clientId":"$CONSUME_GA_CLIENT_ID","clientSecret":"$CONSUME_GA_SECRET","scopes":["https:\/\/www.googleapis.com\/auth\/analytics.readonly"]}

The web logs contain the object: 'verbb\\consume\\clients\\oauth\\Google' => [ 'clientId' => '$CONSUME_GA_CLIENT_ID' 'clientSecret' => '••••••••••••••••••' 'scopes' => [ 0 => [ 'scope' => 'https://www.googleapis.com/auth/analytics.readonly' ] ] 'proxyRedirect' => '$DEV_MODE' ]

engram-design commented 1 year ago

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

carterheron commented 1 year ago

Awesome, much appreciated!

engram-design commented 10 months ago

Fixed in 1.0.4