Social Login using PHP and Google

PHP 
In this tutorial we look at how we can add social login to our web application using Google. We do this in PHP.

The functions file

<?php
require 'vendor/autoload.php';
session_start();

function get_client( $page="auth.php" ){
    $client = new Google_Client();
    $client->setClientId("client-id");
    $client->setClientSecret('client-secret');
    $client->setScopes(array('https://www.googleapis.com/auth/userinfo.email'));
    $client->setRedirectUri('http://' . $_SERVER['HTTP_HOST'] . '/' . $page);
    return $client;
}

function get_auth_url(){
    $client = get_client();
    return $client->createAuthUrl();
}

function get_user_info_object( $authCode ){
    $client = get_client();
    $token = $client->fetchAccessTokenWithAuthCode($authCode);
    $client->setAccessToken($token);
    $oauth = new Google_Service_Oauth2($client);
    return $oauth;
}

Notes

README