2.0 - 2.1 add-on fix (Guzzle)

PhilCanavan

Aspirant
Joined
Jun 23, 2015
Messages
46
So I'm looking at an unmaintained app designed for 2.0. However the script to connect to an external account gives errors. After some research I found the script refers to an older version of Guzzle.

Does anyone know if much changed in this element when XF updated it? I'm worried whole php file needs rewriting.

The error is around
GuzzleHttp\Client::request() and the setdefault option

Is there some simple replacement I can try or will it need an entire rework from scratch?

Thanks.
 

PhilCanavan

Aspirant
Joined
Jun 23, 2015
Messages
46
It's the OpenXBL script. It connects to xbl.io to pull users xbox info like gamerscore. It loads xbox.com to approve the app then fails.

I'm not on my PC at the minute but i'll attach the file in question in the morning.
 

Pete

Flavours of Forums Forever
Joined
Sep 9, 2013
Messages
2,792
If you're just bumping Guzzle a couple of versions it should be fine - if you can post it I'll try to remember to take a look since I do a fair amount with Guzzle.
 

PhilCanavan

Aspirant
Joined
Jun 23, 2015
Messages
46
I can't attach the php file, so it's a video of the connected accounts folder. It's the one inside Provider folder :)
 

Attachments

  • ConnectedAccount.zip
    5 KB · Views: 4

Pete

Flavours of Forums Forever
Joined
Sep 9, 2013
Messages
2,792
I can't test this because I don't have credentials to test it with, however I think you can get by with upgrading this to Guzzle 6+ by replacing the entire requestAccessToken() function in OpenXBL.php with the following:

Code:
    public function requestAccessToken(StorageState $storageState, $code)
    {
        $client = \XF::app()->http()->client();
        try {
            $response = $client->request('POST', $this->base_url . 'app/claim', [
                'json' => [
                    "code" => $code,
                    "app_key" => $storageState->getProvider()->options['app_key']
                ],
                'verify' => false, // cringe
                'timeout' => 30,
            ]);
            return $this->parseAccessTokenResponse($response->getBody()->getContents());
        } catch (\Exception $e) {
            return $this->parseAccessTokenResponse('');
        }
    }

This is just the same request reformatted for Guzzle 6, where the fluff around manually setting headers and so on is now handled by the json option, the setDefaultOption for verifying peer credentials could probably be left on (hence the cringe) but if it was turned off, it was off for a reason, and wrapped in a try/catch to cope with the previous code turning exceptions off.

Give it a go, let me know - but there is a limit to what I can do here.
 

PhilCanavan

Aspirant
Joined
Jun 23, 2015
Messages
46
It passed the test but dropped server errors
ErrorException: [E_NOTICE] Undefined index: secret
src/XF/SubContainer/OAuth.php:49

Generated by: Phil Canavan
Aug 8, 2021 at 11:29 AM

Stack trace​

#0 src/XF/SubContainer/OAuth.php(49): XF::handlePhpError(8, '[E_NOTICE] Unde...', '/home/philc774/...', 49, Array)
#1 src/XF/Container.php(228): XF\SubContainer\OAuth->XF\SubContainer\{closure}('OpenXBL', Array, Object(XF\Container))
#2 src/XF/SubContainer/OAuth.php(104): XF\Container->create('provider', 'OpenXBL', Array)
#3 src/XF/ConnectedAccount/Provider/AbstractProvider.php(154): XF\SubContainer\OAuth->provider('OpenXBL', Array)
#4 src/XF/ConnectedAccount/ProviderData/AbstractProviderData.php(98): XF\ConnectedAccount\Provider\AbstractProvider->getOAuth(Array)
#5 src/XF/Admin/Controller/ConnectedAccount.php(95): XF\ConnectedAccount\ProviderData\AbstractProviderData->requestFromEndpoint()
#6 src/XF/Mvc/Dispatcher.php(321): XF\Admin\Controller\ConnectedAccount->actionPerformTest(Object(XF\Mvc\ParameterBag))
#7 src/XF/Mvc/Dispatcher.php(248): XF\Mvc\Dispatcher->dispatchClass('XF:ConnectedAcc...', 'PerformTest', Object(XF\Mvc\RouteMatch), Object(XF\Admin\Controller\ConnectedAccount), NULL)
#8 src/XF/Mvc/Dispatcher.php(100): XF\Mvc\Dispatcher->dispatchFromMatch(Object(XF\Mvc\RouteMatch), Object(XF\Admin\Controller\ConnectedAccount), NULL)
#9 src/XF/Mvc/Dispatcher.php(50): XF\Mvc\Dispatcher->dispatchLoop(Object(XF\Mvc\RouteMatch))
#10 src/XF/App.php(2177): XF\Mvc\Dispatcher->run()
#11 src/XF.php(390): XF\App->run()
#12 admin.php(13): XF::runApp('XF\\Admin\\App')
#13 {main}

Now I connected my XBL account and it shows on the leaderboards so superb stuff. :)

However when on my test account with another xbox account
There is no valid connected account request available. Please try again.

Same server errors as above. So close to fully working haha. Thanks you!
 

Pete

Flavours of Forums Forever
Joined
Sep 9, 2013
Messages
2,792
Well, the lack of secret stems from the following setup:

Code:
        return [

            'key' => $provider->options['app_key'],

            'redirect' => $redirectUri ?: $this->getRedirectUri($provider)

        ];

This is a bit weird for an OAuth2 setup but if it really doesn't have a secret, just adding like so:

Code:
        return [

            'key' => $provider->options['app_key'],

            'secret' => '',

            'scopes' => [],

            'redirect' => $redirectUri ?: $this->getRedirectUri($provider)

        ];

might solve your warning in the logs (since key/secret/scopes/redirect are the standard things in an OAuth2 request).

As for what's actually wrong, I think that's beyond the scope of what I can look at, I'm afraid. :(
 
Top