Page 1 of 2

[Fixed] Buddies Scope Issue

Posted: 30 Jun 2013, 23:26
by steeffeen
hey there,

i'm having small problems with my maniaconnect authentication :?

the basic code:

Code: Select all

try {
	$maniaconnect = new \Maniaplanet\WebServices\ManiaConnect\Player(API_USER, API_PASS);

	$player = $maniaconnect->getPlayer();

	if ($player) {
		$buddies = $maniaconnect->getBuddies();
		// Do stuff with buddies
	} else {
		$loginURL = $maniaconnect->getLoginURL("basic buddies");
		// Display link for granting access
	}
} catch (\Maniaplanet\WebServices\Exception $e) {
	// Display error
}
it's pretty much the default way to retrieve information via maniaconnect but as soon as the player logged in and $buddies = $maniaconnect->getBuddies(); is executed there is a 401 unauthorized exception thrown every first time
after loading the page again it works fine

i tried retrying directly (without the need of reloading the page manually) with an extra try-catch but it doesn't help

Code: Select all

try {
	$buddies = $maniaconnect->getBuddies();
}
catch (\Maniaplanet\WebServices\Exception $e) {
	switch ($e->getHTTPStatusCode()) {
		case 401: {
			$buddies = $maniaconnect->getBuddies();
			break;
		}
		default: {
			throw $e;
			break;
		}
	}
}
the retry call throws the exception, too

maybe it has something to do with the redirection uri as it only appears right after clicking on the login button.. but the stuff of the basic scope is retrieved properly without problems..

any ideas why it's behaving like that?
thanks in advance

steff

p.s. you can see the issue in action on my manialink RockPaperScissors (Vs. Buddy) // manialink is down by now

// Edit: fixed typo

Re: Buddies Scope Issue

Posted: 25 Mar 2014, 10:28
by magnetik
Humm, I don't really get it.

I tried with the following, wich is kind of the same as the minimal example:

Code: Select all

<?php
/**
 * Maniaplanet Web Services SDK for PHP
 *
 * @copyright   Copyright (c) 2009-2011 NADEO (http://www.nadeo.com)
 * @license     http://www.gnu.org/licenses/lgpl.html LGPL License 3
 * @author      $Author$:
 * @version     $Revision$:
 * @date        $Date$:
 */
require_once __DIR__.'/../../../libraries/autoload.php';

define('API_USERNAME', );
define('API_PASSWORD', );
define('SCOPE', 'basic buddies');

try
{
	$trackmania = new \Maniaplanet\WebServices\ManiaConnect\Player(API_USERNAME, API_PASSWORD);

	// URLs to log in and out
	$loginURL = $trackmania->getLoginURL(SCOPE);
	$logoutURL = $trackmania->getLogoutURL();
	
	if(isset($_GET['logout']))
	{
		$trackmania->logout();
		header('Location: '.$logoutURL);
		exit;
	}

	// Retrive player information. If the user is not logged in, it will return false
	$player = $trackmania->getPlayer();
	
}
catch(\Maniaplanet\WebServices\Exception $e)
{
	$player = null;
	// Uncomment to debug...
	//var_dump($e);
}
?>
<?php if(array_key_exists('HTTP_USER_AGENT', $_SERVER) && substr($_SERVER['HTTP_USER_AGENT'],
		0, 11) == 'ManiaPlanet'): ?>
<manialink version="0">
	<timeout>0</timeout>
	<frame posn="0 25 0">
		<label sizen="70 3"  halign="center" 
			   text="$o$ff0ManiaConnect example" />
		<?php if($player): ?>
		<label sizen="70 3" posn="0 -5 0"  halign="center" text="Hello <?php echo $player->login ?>" />
		<label sizen="70 70" posn="0 -10 0" autonewline="1" halign="center" 
			   text="<?php echo print_r($player, true) ?>" />
		<?php else: ?>
			<label sizen="40 3" posn="0 -5 0"  halign="center" text="Login" manialink="<?php echo htmlentities($loginURL) ?>"/>
		<?php endif ?>
	</frame>
</manialink>
<?php else: ?>
	<html> 
		<head>
			<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
			<title>ManiaConnect example</title>
		</head>
		<body>
			<h1>ManiaConnect example</h1>

			<?php if($player): ?>
				<h3>Hello <?php echo $player->login ?></h3>
				<p>You are connected with your Maniaplanet account.</p>
				<pre><?php print_r($player) ?></pre>
				<pre><?php print_r($trackmania->getBuddies()) ?></pre>
				<p>
					<form action="" method="post">
						<input type="hidden" name="logout" value="1" />
						<input type="submit" name="submit" value="Logout" />
					</form>
				</p>
			<?php else: ?>
				<p>
					<a href="<?php echo $loginURL ?>">Login with your Maniaplanet account</a>
				</p>
			<?php endif ?>

		</body>
	</html>
<?php endif ?>
and I just got the list of buddies without any double request of any kind.

Re: Buddies Scope Issue

Posted: 25 Mar 2014, 18:04
by steeffeen
hey
thanks for the example
(the logout doesn't work in the code because of GET & POST mixup)

i've put it on my server and only slightly adjusted it to print exceptions
http://manialinks.steeffeen.com/scopetest.php
scopetest

don't know what's happening for you but i get an exception for the buddies list

screen@browser
screen@game

Re: Buddies Scope Issue

Posted: 25 Mar 2014, 18:09
by magnetik
Could you post your code?

What's your php version?

Re: Buddies Scope Issue

Posted: 25 Mar 2014, 18:16
by steeffeen
this host is running PHP 5.5.2
kremsy encountered it on a 5.4.4-14+deb7u8

Code: Select all

<?php
/**
* Maniaplanet Web Services SDK for PHP
*
* @copyright   Copyright (c) 2009-2011 NADEO (http://www.nadeo.com)
* @license     http://www.gnu.org/licenses/lgpl.html LGPL License 3
* @author      $Author$:
* @version     $Revision$:
* @date        $Date$:
*/
require_once __DIR__.'/includes/maniaplanet-ws-sdk.php';

define('API_USERNAME', '');
define('API_PASSWORD', '');
define('SCOPE', 'basic buddies');

$ex = null;
$player = null;
$buddies = null;

try
{
   $trackmania = new \Maniaplanet\WebServices\ManiaConnect\Player(API_USERNAME, API_PASSWORD);

   // URLs to log in and out
   $loginURL = $trackmania->getLoginURL(SCOPE);
   $logoutURL = $trackmania->getLogoutURL();
   
   if(isset($_GET['logout']))
   {
      $trackmania->logout();
      header('Location: '.$logoutURL);
      exit;
   }

   // Retrive player information. If the user is not logged in, it will return false
   $player = $trackmania->getPlayer();
   if ($player) $buddies = $trackmania->getBuddies();
   
}
catch(\Maniaplanet\WebServices\Exception $e)
{
	$ex = $e;
   // Uncomment to debug...
//    var_dump($e);
}
?>
<?php if(array_key_exists('HTTP_USER_AGENT', $_SERVER) && substr($_SERVER['HTTP_USER_AGENT'],
      0, 11) == 'ManiaPlanet'): ?>
<manialink version="0">
   <timeout>0</timeout>
   <frame posn="0 25 0">
      <label sizen="70 3"  halign="center" 
            text="$o$ff0ManiaConnect example" />
      <?php if($player): ?>
      <label sizen="70 3" posn="0 -5 0"  halign="center" text="Hello <?php echo $player->login ?>" />
      <label sizen="70 70" posn="-40 -10 0" autonewline="1" halign="center" 
            text="<?php echo print_r($player, true) ?>" />
      <label sizen="70 70" posn="40 -10 0" autonewline="1" halign="center" 
            text="<?php echo print_r($buddies, true) ?>" />
      <label posn="40 10 0" halign="center" 
            manialink="scopetest?logout" text="logout" />
      <?php else: ?>
         <label sizen="40 3" posn="0 -5 0"  halign="center" text="Login" manialink="<?php echo htmlentities($loginURL) ?>"/>
      <?php endif ?>
      <label sizen="70 70" posn="0 -20 0" autonewline="1" halign="center" 
            text="<?php echo print_r($ex, true) ?>" />
   </frame>
</manialink>
<?php else: ?>
   <html> 
      <head>
         <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
         <title>ManiaConnect example</title>
      </head>
      <body>
         <h1>ManiaConnect example</h1>

         <?php if($player): ?>
            <h3>Hello <?php echo $player->login ?></h3>
            <p>You are connected with your Maniaplanet account.</p>
            <pre><?php print_r($player) ?></pre>
            <pre><?php print_r($buddies) ?></pre>
            <p>
               <form action="" method="get">
                  <input type="hidden" name="logout" value="1" />
                  <input type="submit" name="submit" value="Logout" />
               </form>
            </p>
         <?php else: ?>
            <p>
               <a href="<?php echo $loginURL ?>">Login with your Maniaplanet account</a>
            </p>
         <?php endif ?>
				<p><?php print_r($ex); ?></p>
      </body>
   </html>
<?php endif ?>
so did you get an exception, too?

Re: Buddies Scope Issue

Posted: 25 Mar 2014, 18:31
by magnetik
I've tested with PHP 5.3. If you can dump your phpinfo it would be great

Re: Buddies Scope Issue

Posted: 25 Mar 2014, 18:35
by steeffeen
i've sent you a link to a live version in PM
did you get an exception on my host, too? (or is your login immune against this?^^)

Re: Buddies Scope Issue

Posted: 25 Mar 2014, 18:38
by magnetik
Nah I have the error.

If you can try with php 5.3, I won't be able to test before tomorrow.

Could you produce the logs of $method, $ressource and $params before the execute in executeOauth2 in Client.php ?

I'm suspecting an issue with the session.

Re: Buddies Scope Issue

Posted: 25 Mar 2014, 18:51
by steeffeen
var_dump'ing the requested variables now

//Edit: switched to 5.3, still happening