webfox / laravel-xero-oauth2

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

Invalid response received from Authorization Server. Expected JSON. #53

Closed Duncan-dev1 closed 8 months ago

Duncan-dev1 commented 3 years ago

I am new to Xero and chose to use this wrapper package and configured as outlined in the docs,after the user chooses the xero app however,my redirect url https://{my-domain}/xero/auth/callback returns this error 'Invalid response received from Authorization Server. Expected JSON.' Everything is at default at the moment Do i have to do some more configurations?Where?

hailwood commented 3 years ago

Unfortunately that's not enough information for me.

Are you able to provide a stack trace?

Duncan-dev1 commented 3 years ago

This is my logs: `[2021-05-06 04:58:07] local.ERROR: Invalid response received from Authorization Server. Expected JSON. {"exception":"[object] (UnexpectedValueException(code: 0): Invalid response received from Authorization Server. Expected JSON. at C:\xampp\htdocs\laravuex\vendor\league\oauth2-client\src\Provider\AbstractProvider.php:539) [stacktrace]

0 C:\xampp\htdocs\laravuex\vendor\webfox\laravel-xero-oauth2\src\Controllers\AuthorizationCallbackController.php(27): League\OAuth2\Client\Provider\AbstractProvider->getAccessToken(Object(League\OAuth2\Client\Grant\AuthorizationCode), Array)

1 C:\xampp\htdocs\laravuex\vendor\laravel\framework\src\Illuminate\Routing\Controller.php(54): Webfox\Xero\Controllers\AuthorizationCallbackController->__invoke(Object(Illuminate\Http\Request), Object(Webfox\Xero\Oauth2CredentialManagers\FileStore), Object(XeroAPI\XeroPHP\Api\IdentityApi), Object(Webfox\Xero\Oauth2Provider))

2 C:\xampp\htdocs\laravuex\vendor\laravel\framework\src\Illuminate\Routing\ControllerDispatcher.php(45): Illuminate\Routing\Controller->callAction('__invoke', Array)

3 C:\xampp\htdocs\laravuex\vendor\laravel\framework\src\Illuminate\Routing\Route.php(239): Illuminate\Routing\ControllerDispatcher->dispatch(Object(Illuminate\Routing\Route), Object(Webfox\Xero\Controllers\AuthorizationCallbackController), '__invoke')

4 C:\xampp\htdocs\laravuex\vendor\laravel\framework\src\Illuminate\Routing\Route.php(196): Illuminate\Routing\Route->runController()

5 C:\xampp\htdocs\laravuex\vendor\laravel\framework\src\Illuminate\Routing\Router.php(685): Illuminate\Routing\Route->run()

6 C:\xampp\htdocs\laravuex\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(128): Illuminate\Routing\Router->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))

7 C:\xampp\htdocs\laravuex\vendor\laravel\framework\src\Illuminate\Routing\Middleware\SubstituteBindings.php(41): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))

8 C:\xampp\htdocs\laravuex\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(167): Illuminate\Routing\Middleware\SubstituteBindings->handle(Object(Illuminate\Http\Request), Object(Closure))

9 C:\xampp\htdocs\laravuex\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\VerifyCsrfToken.php(78): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))

10 C:\xampp\htdocs\laravuex\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(167): Illuminate\Foundation\Http\Middleware\VerifyCsrfToken->handle(Object(Illuminate\Http\Request), Object(Closure))

11 C:\xampp\htdocs\laravuex\vendor\laravel\framework\src\Illuminate\View\Middleware\ShareErrorsFromSession.php(49): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))

12 C:\xampp\htdocs\laravuex\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(167): Illuminate\View\Middleware\ShareErrorsFromSession->handle(Object(Illuminate\Http\Request), Object(Closure))

13 C:\xampp\htdocs\laravuex\vendor\laravel\framework\src\Illuminate\Session\Middleware\StartSession.php(116): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))

14 C:\xampp\htdocs\laravuex\vendor\laravel\framework\src\Illuminate\Session\Middleware\StartSession.php(62): Illuminate\Session\Middleware\StartSession->handleStatefulRequest(Object(Illuminate\Http\Request), Object(Illuminate\Session\Store), Object(Closure))

15 C:\xampp\htdocs\laravuex\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(167): Illuminate\Session\Middleware\StartSession->handle(Object(Illuminate\Http\Request), Object(Closure))

16 C:\xampp\htdocs\laravuex\vendor\laravel\framework\src\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse.php(37): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))

17 C:\xampp\htdocs\laravuex\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(167): Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse->handle(Object(Illuminate\Http\Request), Object(Closure))

18 C:\xampp\htdocs\laravuex\vendor\laravel\framework\src\Illuminate\Cookie\Middleware\EncryptCookies.php(67): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))

19 C:\xampp\htdocs\laravuex\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(167): Illuminate\Cookie\Middleware\EncryptCookies->handle(Object(Illuminate\Http\Request), Object(Closure))

20 C:\xampp\htdocs\laravuex\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(103): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))

21 C:\xampp\htdocs\laravuex\vendor\laravel\framework\src\Illuminate\Routing\Router.php(687): Illuminate\Pipeline\Pipeline->then(Object(Closure))

22 C:\xampp\htdocs\laravuex\vendor\laravel\framework\src\Illuminate\Routing\Router.php(662): Illuminate\Routing\Router->runRouteWithinStack(Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request))

23 C:\xampp\htdocs\laravuex\vendor\laravel\framework\src\Illuminate\Routing\Router.php(628): Illuminate\Routing\Router->runRoute(Object(Illuminate\Http\Request), Object(Illuminate\Routing\Route))

24 C:\xampp\htdocs\laravuex\vendor\laravel\framework\src\Illuminate\Routing\Router.php(617): Illuminate\Routing\Router->dispatchToRoute(Object(Illuminate\Http\Request))

25 C:\xampp\htdocs\laravuex\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php(165): Illuminate\Routing\Router->dispatch(Object(Illuminate\Http\Request))

26 C:\xampp\htdocs\laravuex\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(128): Illuminate\Foundation\Http\Kernel->Illuminate\Foundation\Http\{closure}(Object(Illuminate\Http\Request))

27 C:\xampp\htdocs\laravuex\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\TransformsRequest.php(21): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))

28 C:\xampp\htdocs\laravuex\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(167): Illuminate\Foundation\Http\Middleware\TransformsRequest->handle(Object(Illuminate\Http\Request), Object(Closure))

29 C:\xampp\htdocs\laravuex\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\TransformsRequest.php(21): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))

30 C:\xampp\htdocs\laravuex\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(167): Illuminate\Foundation\Http\Middleware\TransformsRequest->handle(Object(Illuminate\Http\Request), Object(Closure))

31 C:\xampp\htdocs\laravuex\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\ValidatePostSize.php(27): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))

32 C:\xampp\htdocs\laravuex\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(167): Illuminate\Foundation\Http\Middleware\ValidatePostSize->handle(Object(Illuminate\Http\Request), Object(Closure))

33 C:\xampp\htdocs\laravuex\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode.php(63): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))

34 C:\xampp\htdocs\laravuex\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(167): Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode->handle(Object(Illuminate\Http\Request), Object(Closure))

35 C:\xampp\htdocs\laravuex\vendor\fruitcake\laravel-cors\src\HandleCors.php(37): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))

36 C:\xampp\htdocs\laravuex\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(167): Fruitcake\Cors\HandleCors->handle(Object(Illuminate\Http\Request), Object(Closure))

37 C:\xampp\htdocs\laravuex\vendor\fideloper\proxy\src\TrustProxies.php(57): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))

38 C:\xampp\htdocs\laravuex\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(167): Fideloper\Proxy\TrustProxies->handle(Object(Illuminate\Http\Request), Object(Closure))

39 C:\xampp\htdocs\laravuex\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(103): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))

40 C:\xampp\htdocs\laravuex\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php(140): Illuminate\Pipeline\Pipeline->then(Object(Closure))

41 C:\xampp\htdocs\laravuex\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php(109): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter(Object(Illuminate\Http\Request))

42 C:\xampp\htdocs\laravuex\public\index.php(55): Illuminate\Foundation\Http\Kernel->handle(Object(Illuminate\Http\Request))

43 C:\xampp\htdocs\laravuex\server.php(21): require_once('C:\\xampp\\htdocs...')

44 {main}

"} `

hailwood commented 3 years ago

Okay so somehow it's failing to change the code for an access token. Specifically it's this call that's failing - https://github.com/webfox/laravel-xero-oauth2/blob/master/src/Controllers/AuthorizationCallbackController.php#L27

I suggest editing the vendor directory temporarily to wrap that in a try/catch and dump out the exception and see if you can access the actual response it got.

Duncan-dev1 commented 3 years ago

it still returns the error Invalid response received from Authorization Server. Expected JSON I am starting to think maybe it is something to do with Xero itself,i also cant get an access token when using postman

ramay2088 commented 3 years ago

I observe that if you are using the trial version it gets disconnected after 2,3 days. but if you are using premium account then it works for a longer period of time