Example #1
0
<?php

session_start();
require 'vOauth.php';
$v = new vOauth();
$_SESSION['VOA']['PROVIDER'] = 'v';
$v->setClient(get_option('voa_v_api_id'));
$v->setSecret(get_option('voa_v_api_secret'));
$v->addScope(array(vOauth::SCOPE_PROFILE, vOauth::SCOPE_EMAIL, vOauth::SCOPE_GOOGLEDATA));
$v->setRedirect(rtrim(site_url(), '/') . '/');
define('HTTP_UTIL', get_option('voa_http_util'));
define('CLIENT_ENABLED', get_option('voa_v_api_enabled'));
if (!$_SESSION['VOA']['LAST_URL']) {
    $redirect_url = esc_url($_GET['redirect_to']);
    if (!$redirect_url) {
        $redirect_url = strtok($_SERVER['HTTP_REFERER'], "?");
    }
    $_SESSION['VOA']['LAST_URL'] = $redirect_url;
}
if (!CLIENT_ENABLED) {
    $this->voa_end_login("This third-party authentication provider has not been enabled. Please notify the admin or try again later.");
} elseif (isset($_GET['error_description'])) {
    $this->voa_end_login($_GET['error_description']);
} elseif (isset($_GET['error_message'])) {
    $this->voa_end_login($_GET['error_message']);
} elseif (isset($_GET['code'])) {
    if ($_SESSION['VOA']['STATE'] == $_GET['state']) {
        $v->setCode($_GET['code']);
        $access_token = $v->getToken($_SESSION['VOA']['STATE']);
        $expires_in = $v->getExpiresIn();
        $expires_at = time() + $expires_in;
Example #2
0
<?php

session_start();
require_once '../../vendor/autoload.php';
$v = new vOauth();
/*
 * Change values to what you need
 * scopes are set as constants
 */
$v->setClient("Your client here");
$v->setSecret("Your secret here");
$v->addScope(array("Add scopes here"));
$v->setRedirect("redirect URL here");
if (isset($_GET['logout'])) {
    unset($_SESSION['vACCESS_TOKEN']);
    unset($_SESSION['vREFRESH']);
}
if (isset($_GET['code'])) {
    if ($_GET['state'] === md5('stateGoesHere')) {
        $v->setCode(trim($_GET['code']));
        $_SESSION['vACCESS_TOKEN'] = $v->getToken("stateGoesHere");
        $_SESSION['vREFRESH'] = $v->getRefreshToken();
    } else {
        die("CSRF attack");
    }
    //do something after login
} elseif (isset($_SESSION['vACCESS_TOKEN'])) {
    //set token from session and use it to retrieve data
    $v->setToken($_SESSION['vACCESS_TOKEN']);
    try {
        $vInfo = $v->getVInfo();