Hi, all!
It's been a whole day now and I'm stuck with getting empty results from $postData = file_get_contents('php://input');
My environment is PHP 5.3.3, Apache 2.2.6, localhost.
If anyone can point me in the right direction, it'll be much appreciated.
--
Google API Console Config
Google Identity Toolkit
Account Chooser login widget
This tool helps you to configure your login widget and generate JavaScript code.
Callback URL:
OpenID Realm:
<To be configured>
User status URL:
Login URL:
Signup URL:
Home URL:
Logout URL:
Identity providers:
Gmail,Yahoo
Company name:
Valentinos Pizzaria
Language:
en
In my index.php
<script type="text/javascript">
google.load("identitytoolkit", "1", {packages: ["ac"], language:"en"});
</script>
<script type="text/javascript">
$(function() {
window.google.identitytoolkit.setConfig({
developerKey: "my_developer_key", # Should I post it?
companyName: "Valentinos Pizzaria",
realm: "",
idps: ["Gmail", "Yahoo"],
tryFederatedFirst: true,
useCachedUserStatus: false,
useContextParam: true
});
$("#navbar").accountChooser();
});
</script>
my callback php
#header('Content-type: application/json');
$url = EasyRpService::getCurrentUrl();
#$postData = @file_get_contents('php://input');
$postData = file_get_contents('php://input');
var_dump($postData);
echo "<br><br>";
$result = EasyRpService::verify($url, $postData);
// Turn on for debugging.
var_dump($result);
echo "<br><br>";
die();
class EasyRpService {
// Replace $YOUR_DEVELOPER_KEY
public static function getCurrentUrl() {
$url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 'https://' : 'http://';
$url .= $_SERVER['SERVER_NAME'];
if ($_SERVER['SERVER_PORT'] != '80') {
$url .= ':'. $_SERVER['SERVER_PORT'];
}
$url .= $_SERVER['REQUEST_URI'];
return $url;
}
private static function post($postData) {
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => EasyRpService::$SERVER_URL,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_HTTPHEADER => array('Content-Type: application/json'),
CURLOPT_POSTFIELDS => json_encode($postData)));
$response = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($http_code == '200' && !empty($response)) {
return json_decode($response, true);
}
return NULL;
}
public static function verify($continueUri, $response) {
$request = array();
$request['method'] = 'identitytoolkit.relyingparty.verifyAssertion';
$request['apiVersion'] = 'v1';
$request['params'] = array();
$request['params']['requestUri'] = $continueUri;
$request['params']['postBody'] = $response;
$result = EasyRpService::post($request);
if (!empty($result['result'])) {
return $result['result'];
}
return NULL;
}
} # End Class EasyRpService