[Solved] Different Session Timeouts?

Maniaplanet public API, ManiaConnect system and the open source PHP SDK.

Moderator: NADEO

Post Reply
zocka
Posts: 204
Joined: 15 Jun 2010, 17:56

[Solved] Different Session Timeouts?

Post by zocka » 02 Jan 2015, 15:52

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?
Last edited by zocka on 02 Jan 2015, 21:20, edited 1 time in total.
manialink minigame shatter
my manialink: zockaml
my maniaflash: maniaflash?zocka

TheBigMiike
Posts: 1248
Joined: 06 Mar 2013, 16:12
Location: Vendée | France
Contact:

Re: Different Session Timeouts?

Post by TheBigMiike » 02 Jan 2015, 20:05

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);
}
Image Image

User avatar
m4rcel
Posts: 653
Joined: 15 Jun 2010, 11:12
Contact:

Re: Different Session Timeouts?

Post by m4rcel » 02 Jan 2015, 20:53

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?
ImageImage
Image

zocka
Posts: 204
Joined: 15 Jun 2010, 17:56

Re: Different Session Timeouts?

Post by zocka » 02 Jan 2015, 21:19

That indeed solved the problem, ty :thx:
manialink minigame shatter
my manialink: zockaml
my maniaflash: maniaflash?zocka

User avatar
magnetik
Nadeo
Nadeo
Posts: 1635
Joined: 01 Feb 2012, 19:13
Location: Paris
Contact:

Re: [Solved] Different Session Timeouts?

Post by magnetik » 05 Jan 2015, 09:20

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.
ManiaPlanet technical documentation portal (Dedicated, ManiaLink, ManiaScript, Titles...) -- contribute!

Post Reply

Return to “Maniaplanet Web Services”

Who is online

Users browsing this forum: No registered users and 3 guests