Last active
October 27, 2018 03:43
-
-
Save NirmalAriyathilake/2d193417534f662ea3b5073ddb900c5f to your computer and use it in GitHub Desktop.
OAuth And Social Login - server.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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