Beispiel #1
0
/*	If user doesn't grant the access, redirect to the login page */
if (isset($_GET['error']) && $_GET['error'] == 'access_denied') {
    header("Location: " . SITE_URL . "login/?access_denied");
    exit;
}
// Load configurations
require 'config/client.php';
require 'config/login.php';
require_once 'Google/Client.php';
require_once 'Google/Service/Oauth2.php';
require 'Google/Google.php';
$google = new Google(APP_NAME, CLIENT_ID, CLIENT_SECRET, unserialize(SCOPES), REDIRECT_URI);
if (isset($_GET['code'])) {
    // Exchange the code for access token
    $google->authenticate($_GET['code']);
    $_SESSION['access_token'] = $google->getAccessToken();
    $redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
    header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));
    exit;
}
if ($google->IsAuthenticated()) {
    // Google User is authenticated and authorized
    // Login/Registration can be proceeded
    $gUser = $google->getUserProfile();
    $loginHelper = new LoginHelper($db);
    $user_id = $loginHelper->IsRegistered(OAUTH_GOOGLE, $gUser['id']);
    if ($user_id) {
        // User is already registered - Log in the user
        $redicrect_uri = $loginHelper->Login($user_id, OAUTH_GOOGLE, $gUser['id']);
        header("Location: {$redirect_uri}");
        exit;