Page 1 of 1

[Solved] Different Session Timeouts?

Posted: 02 Jan 2015, 15:52
by zocka
Based on the basic example on github my code is basically

Code: Select all

$maniaConnect = new \Maniaplanet\WebServices\ManiaConnect\Player(WSUSER, WSPASS);
...
$maniaConnectPlayer = $maniaConnect->getPlayer();
...
if ($maniaConnectPlayer) {
  $manialinks = $maniaConnect->getManialinks(); // <-- problem
  var_dump($maniaConnectPlayer);  // <-- no problem
}
 
Within the same session I get the expected result, but after a while (~ 1-2 hours) the marked line throws an "Unauthorized" exception, I can however still access the player data.

What am I doing wrong or what should I do to fix this?

Re: Different Session Timeouts?

Posted: 02 Jan 2015, 20:05
by TheBigMiike
Hi,

It think you forgot the scope "manialinks" when you generated the login URL (see the comment)

Code: Select all

$maniaConnect = new \Maniaplanet\WebServices\ManiaConnect\Player('user', 'pass');
$maniaConnectPlayer = $maniaConnect->getPlayer();

// Generate the login URL
$loginURL = $maniaConnect->getLoginURL('basic manialinks');
// You need to add "manialinks" after "basic"

if ($maniaConnectPlayer) {
  $manialinks = $maniaConnect->getManialinks();
  var_dump($maniaConnectPlayer);
}

Re: Different Session Timeouts?

Posted: 02 Jan 2015, 20:53
by m4rcel
The player data is cached in the session. So additional calls of getPlayer() do not result in additional ManiaConnect requests, but the cached values are used instead. This is only true for the player data; all other data is always re-requested from the webservices. (Dump $_SESSION after you authorized yourself and you should see your player data.)

So in your case, the player data is still present in the session (having getPlayer() not re-requesting it), yet the access token timed out meanwhile, having the following requests get declined. (FYI: The access token lasts 1 hour.)

To solve the problem, you must catch the MPWS exception, and check for 401 Not Authorized. If you encounter it, you must forward the user again to ManiaConnect to get a new access token and thus be able to re-request the data again.


@ Nadeo:
I noticed that the "refresh_token" seems to be always null. Can you confirm that this feature is currently not working/not supported?

Re: Different Session Timeouts?

Posted: 02 Jan 2015, 21:19
by zocka
That indeed solved the problem, ty :thx:

Re: [Solved] Different Session Timeouts?

Posted: 05 Jan 2015, 09:20
by magnetik
The token you get on the Oauth has a different lifetime than the session of your application, so you have to check if it's still valid (with a try catch for instance) before making a call. If the call fails, you have to re-get a token.

About the refresh_token, you have to request the scope "offline" to get one, see the documentation.