I'm trying to implement google+ oauth2 login in my app and I am currently running into a few issues.
I am mainly following what is written here
It seems like the example is using a lot of libraries like twig, but I'm using maining pure php, and I don't think that part is causing any errors
The first issue I faced was that Google_HTTPRequest was not found
.
I read somewhere that composer names it Google_HTTP_Request
, so I changed that and it seemed to have fixed that problem.
Then php was complaining that I was making a static call on a nonstatic function getIo()
.
So I changed to ::
to ->
because that was what made sense to me.
Then I am getting the error
PHP Fatal error: Call to undefined method Google_IO_Curl::authenticatedRequest()
Which probably has something to do with what I changed.
The code I am running is
$google = new Google_Client();
$google->setApplicationName('Hamster Weebly');
$google->setClientId('CLIEnTID');
$google->setClientSecret('himitsudesuyo');
$google->setRedirectUri('postmessage');
$google->authenticate($_POST['AUTH_CODE']);
$token = json_decode($google->getAccessToken());
//$attrbutes = $google->verifyIdToken($token->id_token, '375022219321-us60lmg2cmeoj1aqpl784t7pbl1kg3jv.apps.googleusercontent.com')->getAttributes();
//error_log($attrbutes['payload']['sub']);
$reqUrl = 'https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=' . $token->access_token;
$req = new Google_Http_Request($reqUrl);
$tokenInfo = json_decode($google->getIo()->authenticatedRequest($req)->getResponseBody());
if ($token->error)
{
http_response_code(500);
exit;
}
// Make sure the token we got is for the intended user.
if ($tokenInfo->userid != $gPlusId) {
http_response_code(401);
echo json_encode("Token's user ID doesn't match given user ID");
exit;
}
// Make sure the token we got is for our app.
if ($tokenInfo->audience != CLIENT_ID)
{
http_response_code(401);
echo json_encode("Token's client ID does not match app");
exit;
}
What is my issue?