File: linkback.php

package info (click to toggle)
simplesamlphp 1.19.7-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 42,920 kB
  • sloc: php: 202,044; javascript: 14,867; xml: 2,700; sh: 225; perl: 82; makefile: 70; python: 5
file content (45 lines) | stat: -rw-r--r-- 1,533 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php

/**
 * Handle linkback() response from Twitter.
 */

if (!array_key_exists('AuthState', $_REQUEST) || empty($_REQUEST['AuthState'])) {
    throw new \SimpleSAML\Error\BadRequest('Missing state parameter on twitter linkback endpoint.');
}
$state = \SimpleSAML\Auth\State::loadState(
    $_REQUEST['AuthState'],
    \SimpleSAML\Module\authtwitter\Auth\Source\Twitter::STAGE_INIT
);

// Find authentication source
if (is_null($state) || !array_key_exists(\SimpleSAML\Module\authtwitter\Auth\Source\Twitter::AUTHID, $state)) {
    throw new \SimpleSAML\Error\BadRequest(
        'No data in state for '.\SimpleSAML\Module\authtwitter\Auth\Source\Twitter::AUTHID
    );
}
$sourceId = $state[\SimpleSAML\Module\authtwitter\Auth\Source\Twitter::AUTHID];

/** @var \SimpleSAML\Module\authtwitter\Auth\Source\Twitter|null $source */
$source = \SimpleSAML\Auth\Source::getById($sourceId);
if ($source === null) {
    throw new \SimpleSAML\Error\BadRequest(
        'Could not find authentication source with id '.var_export($sourceId, true)
    );
}

try {
    if (array_key_exists('denied', $_REQUEST)) {
        throw new \SimpleSAML\Error\UserAborted();
    }
    $source->finalStep($state);
} catch (\SimpleSAML\Error\Exception $e) {
    \SimpleSAML\Auth\State::throwException($state, $e);
} catch (\Exception $e) {
    \SimpleSAML\Auth\State::throwException(
        $state,
        new \SimpleSAML\Error\AuthSource($sourceId, 'Error on authtwitter linkback endpoint.', $e)
    );
}

\SimpleSAML\Auth\Source::completeAuth($state);