Ejemplo n.º 1
0
 * @file
 * Take the user when they return from Mendeley. Get access tokens.
 * Verify credentials and redirect to based on response from Mendeley.
 */
/* Start session and load lib */
session_start();
require_once '../mendeleyoauth/mendeleyoauth.php';
require_once 'config.inc.php';
/* If the oauth_token is old redirect to the connect page. */
if (isset($_REQUEST['oauth_token']) && $_SESSION['oauth_token'] !== $_REQUEST['oauth_token']) {
    $_SESSION['oauth_status'] = 'oldtoken';
    header('Location: ./clearsessions.php');
}
/* Create MendeleyOauth object with app key/secret and token key/secret from default phase */
$connection = new MendeleyOauth(CONSUMER_KEY, CONSUMER_SECRET, $_SESSION['oauth_token'], $_SESSION['oauth_token_secret'], HTTP_PROXY);
/* Request access tokens from Mendeley */
$access_token = $connection->getAccessToken($_REQUEST['oauth_verifier']);
/* Save the access tokens. Normally these would be saved in a database for future use. */
$_SESSION['access_token'] = $access_token;
/* Remove no longer needed request tokens */
unset($_SESSION['oauth_token']);
unset($_SESSION['oauth_token_secret']);
/* If HTTP response is 200 continue otherwise send to connect page to retry */
if (200 == $connection->http_code) {
    /* The user has been verified and the access tokens can be saved for future use */
    $_SESSION['status'] = 'verified';
    header('Location: ./index.php');
} else {
    /* Save HTTP status for error dialog on connnect page.*/
    header('Location: ./clearsessions.php');
}
Ejemplo n.º 2
0
} else {
    /* Get temporary credentials. */
    $connection = new MendeleyOauth(CONSUMER_KEY, CONSUMER_SECRET, NULL, NULL, HTTP_PROXY);
    $request_token = $connection->getRequestToken();
    $request_token['oauth_token'];
    $request_token['oauth_token_secret'];
    $url = $connection->getAuthorizeURL($request_token['oauth_token']);
    // URL to get token...(paste this into browser)
    echo "Paste this URL into your web browser, then enter token below\n";
    echo $url . "\n";
    $f = popen("read; echo \$REPLY", "r");
    $input = fgets($f, 100);
    pclose($f);
    echo "Entered: {$input}\n";
    $request_token['oauth_verifier'] = trim($input);
    $access_token = $connection->getAccessToken($request_token['oauth_verifier']);
    $file = fopen($filename, "w") or die("could't open file --\"{$filename}\"");
    fwrite($file, json_encode($access_token));
    fclose($file);
}
// Public resources
// Look up a DOI
$doi = '10.1186/2047-217X';
$url = 'http://api.mendeley.com/oapi/documents/details/' . urlencode(urlencode($doi)) . '/?type=doi&consumer_key=' . CONSUMER_KEY;
echo "Fetch document with DOI {$doi}:\n";
echo json_format($connection->http($url, 'GET'));
echo "\n";
// Look up a PMID
$pmid = 17397521;
$url = 'http://api.mendeley.com/oapi/documents/details/' . $pmid . '/?type=pmid&consumer_key=' . CONSUMER_KEY;
echo "Fetch document with PMID {$pmid}:\n";