Skip to content

Instantly share code, notes, and snippets.

@DanielMartinus
Created October 9, 2015 13:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DanielMartinus/a2686368ab19571445c2 to your computer and use it in GitHub Desktop.
Save DanielMartinus/a2686368ab19571445c2 to your computer and use it in GitHub Desktop.
$client_id = '';
$client_secret = '';
$client = new Google_Client();
$client->setClientId($client_id);
$client->setClientSecret($client_secret);
$client->setScopes('https://www.googleapis.com/auth/plus.login');
$client->setState('offline');
$plus = new Google_Service_Plus($client);
$client->authenticate($_POST['token']);
$token = json_decode($client->getAccessToken());
$accessToken = $token->access_token;
$tokenType = $token->token_type;
$expires_in = $token->expires_in;
$idToken = $token->id_token;
$refresh_token = $token->refresh_token;
$created = $token->created;
$ticket = $client->verifyIdToken($idToken);
$userId = null;
if ($ticket) {
$data = $ticket->getAttributes();
$userId = $data['payload']['sub']; // user ID
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment