$client->client_id = '';
$application_line = __LINE__;
$client->client_secret = '';
if (strlen($client->client_id) == 0 || strlen($client->client_secret) == 0) {
    die('Please go to Google APIs console page ' . 'http://code.google.com/apis/console in the API access tab, ' . 'create a new client ID, and in the line ' . $application_line . ' set the client_id to Client ID and client_secret with Client Secret. ' . 'The callback URL must be ' . $client->redirect_uri . ' but make sure ' . 'the domain is valid and can be resolved by a public DNS.');
}
/* API permissions
 */
$client->scope = 'https://www.googleapis.com/auth/userinfo.email ' . 'https://www.googleapis.com/auth/userinfo.profile';
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://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);
Exemplo n.º 2
0
$client->database = $databaseDetails;
$client->server = 'Facebook';
$client->offline = true;
$client->debug = true;
$client->debug_http = true;
$client->redirect_uri = Open::URL('/oauth/login_with_facebook');
$client->client_id = 'fbAppID';
$client->client_secret = 'fbAppSecret';
$client->scope = 'user_about_me,email,user_birthday,user_location,publish_actions';
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://graph.facebook.com/me', 'GET', array(), array('FailOnAccessError' => true), $user);
            if ($success) {
                $location = $_SESSION['continue'];
                $email = $user->email;
                $name = $user->name;
                $gender = $user->gender;
                if (\Fr\LS::userExists($email)) {
                    /**
                     * Since user exists, we log him/her in
                     */
                    \Fr\LS::login($email, "");
                    $who = $_SESSION['logSyscuruser'];
                    $sql = $OP->dbh->prepare("UPDATE `oauth_session` SET `user` = ? WHERE `server` = ? AND `access_token` = ?");
                    $sql->execute(array($who, "Facebook", $client->access_token));
                    $OP->redirect($location);
                } else {
$client->debug = true;
$client->debug_http = true;
$client->redirect_uri = 'http://' . $_SERVER['HTTP_HOST'] . dirname(strtok($_SERVER['REQUEST_URI'], '?')) . '/mysqli_login_with_twitter.php';
$client->client_id = '';
$application_line = __LINE__;
$client->client_secret = '';
if (strlen($client->client_id) == 0 || strlen($client->client_secret) == 0) {
    die('Please go to Twitter Apps page https://dev.twitter.com/apps/new , ' . 'create an application, and in the line ' . $application_line . ' set the client_id to Consumer key and client_secret with Consumer secret. ' . 'The Callback URL must be ' . $client->redirect_uri . ' If you want to post to ' . 'the user timeline, make sure the application you create has write permissions');
}
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);
            /*
             * 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);