PHP oauth2 authorization returns html login


Hi there,

I’m trying to implement an integration between airvantage and a local network intranet.
I’ve been following the instructions on the various api documents but all seem to brush over the log in requirement.

Could someone shed some light on how to authenticate and get a token in PHP please?

This is what I’m doing, and I’m expecting to receive the code for the token request.

$auth_url = '' . $client_id . '&response_type=code&redirect_uri=' . $redirect_uri;

$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $auth_url);
$result = curl_exec($curl);

Thank you in advance.


Did you succeeded?? I suffer from the same problem, and not able to find a solution…
Please, provide some additional info, if you were successful with this.
Thank you!



here a sample code which may help you:
// Setup a handle for CURL

// An AirVantage M2M Cloud authorization temporary code is passed on the URL (we are in the callback of the OAuth process)
  	// Using it to require a token
  	$authUrl = "" . $authCode
  		. "&client_id=" . $clientId . "&client_secret=" . $secretKey;
  	$response = decodeAVJson($curl_handle, $authUrl);

  	if (!empty($response->access_token))
		$token = $response->access_token;
		$validity = time() + $response->expires_in;
		$refresh = $response->refresh_token;
		// Store the token info into the session
		$_SESSION['AirVantageToken'] = $token;
		$_SESSION['AirVantageTokenValidity'] = $validity;
		$_SESSION['AirVantageRefreshToken'] = $refresh;
		print "AirVantage authentication succeeded and token retrieved<br />";

		return $token;

// Returns an objet decoded from the Ajax response from AirVantage to the REST query passed in the $url
// parameter
function decodeAVJson($curl_handle, $url)
// uncomment to trace each query sent to AV
print "HTTP REQUEST = " . $url . “

	$json = curl_exec($curl_handle);
	// uncomment to trace each JSON responses received from AV
	print "<font color='brown'><i>JSON RECEIVED = " . $json . "</i></font><br/>";

	if($json !== false)
		return json_decode($json);
		return "Could not communicate with AirVantage (CURL error): " . curl_error($curl_handle);


Hi there,

I believe I did but it’s been so long since I figured it out that I can’t remember what the solution was now.
The comment from rjacolin might help but I’ve not tried it. If I find the answer, I will post it for people having this issue in the future.