コード例 #1
0
        if (strlen($client->authorization_error)) {
            $client->error = $client->authorization_error;
            $success = false;
        } elseif (strlen($client->access_token)) {
            $success = $client->CallAPI('https://www.googleapis.com/oauth2/v1/userinfo', 'GET', array(), array('FailOnAccessError' => true), $user);
            /*
             * Once you were able to access the user account using the API
             * you should associate the current OAuth access token a specific
             * user, so you can call the API without the user presence, just
             * specifying the user id in your database.
             *
             * In this example the user id is 1 . Your application should
             * determine the right user is to associate.
             */
            if ($success) {
                $success = $client->SetUser(1);
            }
        }
    }
    $success = $client->Finalize($success);
}
if ($client->exit) {
    exit;
}
if ($success) {
    ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Google OAuth client results</title>
</head>
コード例 #2
0
                    $OP->redirect($location);
                } else {
                    /**
                     * Make it DD/MM/YYYY format
                     */
                    $birthday = date('d/m/Y', strtotime($user->birthday));
                    $image = get_headers("https://graph.facebook.com/me/picture?width=200&height=200&access_token=" . $client->access_token, 1);
                    /* Facebook Redirects the above URL to the image URL, We get that new URL ! PHP is Magic */
                    $image = $image['Location'];
                    /* An array containing user details that will made in to JSON */
                    $userArray = array("joined" => date("Y-m-d H:i:s"), "gen" => $gender, "birth" => $birthday, "img" => $image);
                    $json = json_encode($userArray);
                    \Fr\LS::register($email, "", array("name" => $name, "udata" => $json, "seen" => ""));
                    /* Login the user */
                    \Fr\LS::login($email, "");
                    $client->SetUser($id);
                    $OP->redirect($location);
                }
            }
        }
    }
    $success = $client->Finalize($success);
}
if ($client->exit) {
    $OP->ser("Something Happened", "<a href='" . $client->redirect_uri . "'>Try Again</a>");
}
if (!$success) {
    ?>
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 <html>
  <head>
コード例 #3
0
$client->server = 'Twitter';
$client->offline = true;
$client->debug = true;
$client->debug_http = true;
$client->client_id = 'twitterClientID';
$client->client_secret = 'twitterClientSecret';
$client->redirect_uri = Open::URL('/oauth/login_with_twitter');
if ($success = $client->Initialize()) {
    if ($success = $client->Process()) {
        if (strlen($client->authorization_error)) {
            $client->error = $client->authorization_error;
            $success = false;
        } elseif (strlen($client->access_token)) {
            $success = $client->CallAPI('https://api.twitter.com/1.1/account/verify_credentials.json', 'GET', array(), array('FailOnAccessError' => true), $user);
            if ($success) {
                $success = $client->SetUser($who);
            }
        }
    }
    $success = $client->Finalize($success);
}
if ($client->exit) {
    $OP->ser("Error", "Something Happened. Try again.");
}
if ($success) {
    if (strlen($client->access_token)) {
        $OP->redirect(HOST . "/home");
    } else {
        echo 'Error: ', $client->error, "\n";
    }
}