Ejemplo n.º 1
0
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;
        if (!$access_token || !$expires_in) {
            $this->voa_end_login("Sorry, we couldn't log you in. Malformed access token result detected. Please notify the admin or try again later.");
        } else {
            $_SESSION['VOA']['ACCESS_TOKEN'] = $access_token;
            $_SESSION['VOA']['EXPIRES_IN'] = $expires_in;
            $_SESSION['VOA']['EXPIRES_AT'] = $expires_at;
            try {
                $vInfo = $v->getVInfo();
                $googleInfo = $v->getGoogleData();
                $oauth_identity = array();
                //universal
                $oauth_identity['provider'] = $_SESSION['VOA']['PROVIDER'];
Ejemplo n.º 2
0
$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();
        echo "you are logged into v. Welcome back " . $vInfo->{'agent'};
    } catch (Exception $e) {
        echo $e->getMessage();
    }