webfox / laravel-xero-oauth2

A Laravel integration for Xero using the Oauth 2.0 spec
MIT License
50 stars 32 forks source link

Handle multiple tenants in XeroAuthorized #74

Closed AbrahamBrookes closed 2 years ago

AbrahamBrookes commented 2 years ago

When I was connecting my app using this library I hit an issue where the oauth credentials were throwing an error: Undefined array key "tenant_id" , because the structure from $oauth->getData() had my tenants as an array, as opposed to the single tenant_id expected:

dd( $oauth->getData() );

// results in 

[
  "token" => "asdasdasdasdasdasd"
  "refresh_token" => null
  "id_token" => "asdasdasdasdasdasdasdaasd"
  "expires" => 1657593567
  "tenants" => [
    0 => [
      "Id" => "asdasdasd-asdasd-asdasd-asdasd-asdasdasda"
      "Name" => "Demo Company (AU)"
    ]
  ]
]

I'm not sure if this is a permanent API change or if the response changes depending on your Xero account settings or what, but this change allows for my integration to proceed without breaking anything else, so I thought I might as well push it!

hailwood commented 2 years ago

Hi @AbrahamBrookes,

You're right this is definitely a bug, It was introduced in #71 by us not updating this so it is a permanent API change.

Rather than setting the ID from the first tenant, can you please remove the tenant_id property and add a tenants property that expects the array?

Cheers!

AbrahamBrookes commented 2 years ago

cool thanks! that's been updated in 334b2c3 and tested working in my project: image

hailwood commented 2 years ago

Thanks @AbrahamBrookes,

That's now been released

AbrahamBrookes commented 2 years ago

Legend! Aw, my first PR package pull. This calls for a celebration 🥃

hailwood commented 2 years ago

Congrats @AbrahamBrookes,

It's a good feeling!