web/callback.php
author ymh <ymh.work@gmail.com>
Thu, 20 Sep 2018 15:11:27 +0200
changeset 1440 4a97b38b8b80
parent 1427 8b3d57a519eb
child 1557 7c67caaafdeb
permissions -rwxr-xr-x
Added tag V06.001 for changeset df4c992749ea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
     1
<?php
563
0dd745105665 Tests for IE9 cookie issues
Raphael Velt <raph.velt@gmail.com>
parents: 557
diff changeset
     2
header('P3P:CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"');
1427
8b3d57a519eb remove dependency to Zend 1. Use composer to reduce the number of dependencies
ymh <ymh.work@gmail.com>
parents: 849
diff changeset
     3
233
10d6fd6ce9ab - put all in a registry
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 229
diff changeset
     4
include_once 'common.php';
1427
8b3d57a519eb remove dependency to Zend 1. Use composer to reduce the number of dependencies
ymh <ymh.work@gmail.com>
parents: 849
diff changeset
     5
use Abraham\TwitterOAuth\TwitterOAuth;
8b3d57a519eb remove dependency to Zend 1. Use composer to reduce the number of dependencies
ymh <ymh.work@gmail.com>
parents: 849
diff changeset
     6
233
10d6fd6ce9ab - put all in a registry
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 229
diff changeset
     7
if(!isset($_REQUEST['rep'])) {
1427
8b3d57a519eb remove dependency to Zend 1. Use composer to reduce the number of dependencies
ymh <ymh.work@gmail.com>
parents: 849
diff changeset
     8
    $rep = $C_default_rep;
233
10d6fd6ce9ab - put all in a registry
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 229
diff changeset
     9
}
10d6fd6ce9ab - put all in a registry
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 229
diff changeset
    10
else {
1427
8b3d57a519eb remove dependency to Zend 1. Use composer to reduce the number of dependencies
ymh <ymh.work@gmail.com>
parents: 849
diff changeset
    11
    $rep = $_REQUEST['rep'];
233
10d6fd6ce9ab - put all in a registry
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 229
diff changeset
    12
}
10d6fd6ce9ab - put all in a registry
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 229
diff changeset
    13
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    14
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    15
if (!empty($_GET) && isset($_SESSION['TWITTER_REQUEST_TOKEN'])) {
1427
8b3d57a519eb remove dependency to Zend 1. Use composer to reduce the number of dependencies
ymh <ymh.work@gmail.com>
parents: 849
diff changeset
    16
8b3d57a519eb remove dependency to Zend 1. Use composer to reduce the number of dependencies
ymh <ymh.work@gmail.com>
parents: 849
diff changeset
    17
8b3d57a519eb remove dependency to Zend 1. Use composer to reduce the number of dependencies
ymh <ymh.work@gmail.com>
parents: 849
diff changeset
    18
    $token = unserialize($_SESSION['TWITTER_REQUEST_TOKEN']);
8b3d57a519eb remove dependency to Zend 1. Use composer to reduce the number of dependencies
ymh <ymh.work@gmail.com>
parents: 849
diff changeset
    19
8b3d57a519eb remove dependency to Zend 1. Use composer to reduce the number of dependencies
ymh <ymh.work@gmail.com>
parents: 849
diff changeset
    20
    if (isset($_REQUEST['oauth_token']) && $token['oauth_token'] !== $_REQUEST['oauth_token']) {
8b3d57a519eb remove dependency to Zend 1. Use composer to reduce the number of dependencies
ymh <ymh.work@gmail.com>
parents: 849
diff changeset
    21
        exit('Invalid callback request. Oops. Sorry.');
8b3d57a519eb remove dependency to Zend 1. Use composer to reduce the number of dependencies
ymh <ymh.work@gmail.com>
parents: 849
diff changeset
    22
    }
8b3d57a519eb remove dependency to Zend 1. Use composer to reduce the number of dependencies
ymh <ymh.work@gmail.com>
parents: 849
diff changeset
    23
8b3d57a519eb remove dependency to Zend 1. Use composer to reduce the number of dependencies
ymh <ymh.work@gmail.com>
parents: 849
diff changeset
    24
    $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $token['oauth_token'], $token['oauth_token_secret']);
8b3d57a519eb remove dependency to Zend 1. Use composer to reduce the number of dependencies
ymh <ymh.work@gmail.com>
parents: 849
diff changeset
    25
    $access_token = $connection->oauth("oauth/access_token", ["oauth_verifier" => $_REQUEST['oauth_verifier']]);
8b3d57a519eb remove dependency to Zend 1. Use composer to reduce the number of dependencies
ymh <ymh.work@gmail.com>
parents: 849
diff changeset
    26
8b3d57a519eb remove dependency to Zend 1. Use composer to reduce the number of dependencies
ymh <ymh.work@gmail.com>
parents: 849
diff changeset
    27
    $_SESSION['TWITTER_ACCESS_TOKEN'] = serialize($access_token);
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    28
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    29
    /**
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    30
     * Now that we have an Access Token, we can discard the Request Token
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    31
     */
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    32
    $_SESSION['TWITTER_REQUEST_TOKEN'] = null;
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    33
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    34
    /**
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    35
     * With Access Token in hand, let's try accessing the client again
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    36
     */
849
973a136cfbd0 Bugfixes
Raphael Velt <raph.velt@gmail.com>
parents: 847
diff changeset
    37
    header('Location: ' . ( isset($_SESSION['TWITTER_REDIRECT_URL']) ? $_SESSION['TWITTER_REDIRECT_URL'] : ( URL_ROOT . "$rep/client.php" ) ) );
1427
8b3d57a519eb remove dependency to Zend 1. Use composer to reduce the number of dependencies
ymh <ymh.work@gmail.com>
parents: 849
diff changeset
    38
0
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    39
} else {
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    40
    /**
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    41
     * Mistaken request? Some malfeasant trying something?
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    42
     */
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    43
    exit('Invalid callback request. Oops. Sorry.');
4eba9c11703f first import
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    44
}