# The 500er appears when using the three legged OAuth2

**URL:** https://forum.mautic.org/t/the-500er-appears-when-using-the-three-legged-oauth2/25909
**Category:** Product Support
**Created:** [November 1, 2022, 9:20am UTC](https://forum.mautic.org/t/the-500er-appears-when-using-the-three-legged-oauth2/25909 "2022-11-01T09:20:56Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![volha](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/volha/32/6820_2.png) [@volha](https://forum.mautic.org/u/volha)
#### Post date: [November 1, 2022, 9:20am UTC](https://forum.mautic.org/t/the-500er-appears-when-using-the-three-legged-oauth2/25909/1 "2022-11-01T09:20:56Z")

</div>

**Your software**  
My Mautic version is: 4.4.3  
My PHP version is: 7.4  
My Database type and version is: Maria DB 10.3

**Your problem**  
I use the integration bundle to integrate the 3rd party service with Mautic.  
Using the three legged OAuth2 to authorize I get the 500er.

 ![image](https://us1.discourse-cdn.com/flex020/uploads/mautic/original/2X/2/24cc97cba66ca6a94380c4c21444876887fce2bc.png)

These errors are showing in the log:  
[2022-11-01 10:29:52] mautic.CRITICAL: Uncaught PHP Exception Symfony\Component\Debug\Exception\FatalThrowableError: “Argument 2 passed to kamermans\OAuth2\Token\RawTokenFactory::\_\_invoke() must be an instance of kamermans\OAuth2\Token\RawToken or null, instance of Mautic\IntegrationsBundle\Auth\Support\Oauth2\Token\IntegrationToken given” at /var/www/html/vendor/kamermans/guzzle-oauth2-subscriber/src/Token/RawTokenFactory.php line 7 {“exception”:"[object] (Symfony\Component\Debug\Exception\FatalThrowableError(code: 0): Argument 2 passed to kamermans\OAuth2\Token\RawTokenFactory::\_\_invoke() must be an instance of kamermans\OAuth2\Token\RawToken or null, instance of Mautic\IntegrationsBundle\Auth\Support\Oauth2\Token\IntegrationToken given at /var/www/html/vendor/kamermans/guzzle-oauth2-subscriber/src/Token/RawTokenFactory.php:7)  
[stacktrace]  
#0 [internal function]: kamermans\OAuth2\Token\RawTokenFactory-\>\_\_invoke(Array, Object(Mautic\IntegrationsBundle\Auth\Support\Oauth2\Token\IntegrationToken))  
#1 /var/www/html/vendor/kamermans/guzzle-oauth2-subscriber/src/OAuth2Handler.php(252): call\_user\_func\_array(Object(kamermans\OAuth2\Token\RawTokenFactory), Array)  
#2 /var/www/html/vendor/kamermans/guzzle-oauth2-subscriber/src/OAuth2Handler.php(270): kamermans\OAuth2\OAuth2Handler-\>tokenFactory(Array, Object(Mautic\IntegrationsBundle\Auth\Support\Oauth2\Token\IntegrationToken))  
#3 /var/www/html/vendor/kamermans/guzzle-oauth2-subscriber/src/OAuth2Handler.php(213): kamermans\OAuth2\OAuth2Handler-\>requestNewAccessToken()  
#4 /var/www/html/vendor/kamermans/guzzle-oauth2-subscriber/src/OAuth2Handler.php(236): kamermans\OAuth2\OAuth2Handler-\>getAccessToken()  
#5 /var/www/html/vendor/kamermans/guzzle-oauth2-subscriber/src/OAuth2Middleware.php(30): kamermans\OAuth2\OAuth2Handler-\>signRequest(Object(GuzzleHttp\Psr7\Request))  
#6 /var/www/html/vendor/guzzlehttp/guzzle/src/PrepareBodyMiddleware.php(35): kamermans\OAuth2\OAuth2Middleware-\>kamermans\OAuth2\{closure}(Object(GuzzleHttp\Psr7\Request), Array)  
#7 /var/www/html/vendor/guzzlehttp/guzzle/src/Middleware.php(31): GuzzleHttp\PrepareBodyMiddleware-\>\_\_invoke(Object(GuzzleHttp\Psr7\Request), Array)  
#8 /var/www/html/vendor/guzzlehttp/guzzle/src/RedirectMiddleware.php(71): GuzzleHttp\Middleware::GuzzleHttp\{closure}(Object(GuzzleHttp\Psr7\Request), Array)  
#9 /var/www/html/vendor/guzzlehttp/guzzle/src/Middleware.php(63): GuzzleHttp\RedirectMiddleware-\>\_\_invoke(Object(GuzzleHttp\Psr7\Request), Array)  
#10 /var/www/html/vendor/guzzlehttp/guzzle/src/HandlerStack.php(75): GuzzleHttp\Middleware::GuzzleHttp\{closure}(Object(GuzzleHttp\Psr7\Request), Array)  
#11 /var/www/html/vendor/guzzlehttp/guzzle/src/Client.php(331): GuzzleHttp\HandlerStack-\>\_\_invoke(Object(GuzzleHttp\Psr7\Request), Array)  
#12 /var/www/html/vendor/guzzlehttp/guzzle/src/Client.php(168): GuzzleHttp\Client-\>transfer(Object(GuzzleHttp\Psr7\Request), Array)  
#13 /var/www/html/vendor/guzzlehttp/guzzle/src/Client.php(187): GuzzleHttp\Client-\>requestAsync(‘GET’, Object(GuzzleHttp\Psr7\Uri), Array)  
#14 /var/www/html/plugins/AivieBexioBundle/Connection/Client.php(52): GuzzleHttp\Client-\>request(‘GET’, ‘[https://api.bex](https://api.bex)…’, Array)  
#15 /var/www/html/plugins/AivieBexioBundle/Integration/Support/AuthSupport.php(34): MauticPlugin\AivieBexioBundle\Connection\Client-\>authenticate(‘’)  
#16 /var/www/html/app/bundles/IntegrationsBundle/Controller/AuthController.php(23): MauticPlugin\AivieBexioBundle\Integration\Support\AuthSupport-\>authenticateIntegration(Object(Symfony\Component\HttpFoundation\Request))  
#17 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(158): Mautic\IntegrationsBundle\Controller\AuthController-\>callbackAction(‘bexio’, Object(Symfony\Component\HttpFoundation\Request))  
#18 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(80): Symfony\Component\HttpKernel\HttpKernel-\>handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)  
#19 /var/www/html/vendor/symfony/http-kernel/Kernel.php(201): Symfony\Component\HttpKernel\HttpKernel-\>handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)  
#20 /var/www/html/app/AppKernel.php(116): Symfony\Component\HttpKernel\Kernel-\>handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)  
#21 /var/www/html/app/middlewares/CORSMiddleware.php(82): AppKernel-\>handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)  
#22 /var/www/html/app/middlewares/CatchExceptionMiddleware.php(34): Mautic\Middleware\CORSMiddleware-\>handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)  
#23 /var/www/html/app/middlewares/Dev/IpRestrictMiddleware.php(52): Mautic\Middleware\CatchExceptionMiddleware-\>handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)  
#24 /var/www/html/app/middlewares/VersionCheckMiddleware.php(58): Mautic\Middleware\Dev\IpRestrictMiddleware-\>handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)  
#25 /var/www/html/app/middlewares/TrustMiddleware.php(42): Mautic\Middleware\VersionCheckMiddleware-\>handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)  
#26 /var/www/html/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Mautic\Middleware\TrustMiddleware-\>handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)  
#27 /var/www/html/vendor/stack/run/src/Stack/run.php(13): Stack\StackedHttpKernel-\>handle(Object(Symfony\Component\HttpFoundation\Request))  
#28 /var/www/html/index\_dev.php(30): Stack\

Steps I have tried to fix the problem:  
Modify the `IntegrationsBundle/Auth/Support/Oauth2/Token/TokenPersistence.php`. Replace `IntegrationToken` to `RawToken`. Works properly after that.
