Skip to content

Instantly share code, notes, and snippets.

@NirmalAriyathilake
Last active October 27, 2018 03:43
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 NirmalAriyathilake/2d193417534f662ea3b5073ddb900c5f to your computer and use it in GitHub Desktop.
Save NirmalAriyathilake/2d193417534f662ea3b5073ddb900c5f to your computer and use it in GitHub Desktop.
OAuth And Social Login - server.php
<?php
require_once 'vendor/autoload.php';
session_start();
if(isset($_POST['idtoken'])){
// Get $id_token via HTTPS POST.
$id_token = $_POST['idtoken'];
$CLIENT_ID = "57064433868-ebkvuv5druld2jah3h8hmt5l71ennfqb.apps.googleusercontent.com";
$client = new Google_Client(['client_id' => $CLIENT_ID]); // Specify the CLIENT_ID of the app that accesses the backend
$profile = $client->verifyIdToken($id_token);
if ($profile) {
$userid = $profile['sub'];
echo $userid;
$_SESSION['profile_name'] = $profile['name'];
$_SESSION['profile_email'] = $profile['email'];
$_SESSION['profile_picture'] = $profile['picture'];
$_SESSION['id_token'] = $id_token;
} else {
echo "invalid";
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment