예제 #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');
예제 #2
0
<?php

/* Start session and load library. */
session_start();
require_once '../mendeleyoauth/mendeleyoauth.php';
require_once 'config.inc.php';
/* Build MendeleyOauth object with client credentials. */
$connection = new MendeleyOauth(CONSUMER_KEY, CONSUMER_SECRET, NULL, NULL, HTTP_PROXY);
/* Get temporary credentials. */
$request_token = $connection->getRequestToken(OAUTH_CALLBACK);
/* Save temporary credentials to session. */
$_SESSION['oauth_token'] = $token = $request_token['oauth_token'];
$_SESSION['oauth_token_secret'] = $request_token['oauth_token_secret'];
/* If last connection failed don't display authorization link. */
switch ($connection->http_code) {
    case 200:
        /* Build authorize URL and redirect user to Mendeley. */
        $url = $connection->getAuthorizeURL($token);
        header('Location: ' . $url);
        break;
    default:
        /* Show notification if something went wrong. */
        echo 'Could not connect to Mendeley. Refresh the page or try again later.';
}
예제 #3
0
require_once '../mendeleyoauth/mendeleyoauth.php';
require_once dirname(__FILE__) . '/config.inc.php';
$connection = NULL;
// We store access tokens in file. If file exists then we should be authenticated, if not
// we need to get a token from the Mendeley site.
$filename = dirname(__FILE__) . '/tokens.json';
if (file_exists($filename)) {
    $file = @fopen($filename, "a+") or die("could't open file --\"{$filename}\"");
    $json = fread($file, filesize($filename));
    fclose($file);
    $access_token = json_decode($json);
    $connection = new MendeleyOauth(CONSUMER_KEY, CONSUMER_SECRET, $access_token->oauth_token, $access_token->oauth_token_secret, HTTP_PROXY);
} 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));
예제 #4
0
/**
 * @file
 * User has successfully authenticated with Twitter. Access tokens saved to session and DB.
 */
/* Load required lib files. */
session_start();
require_once '../mendeleyoauth/mendeleyoauth.php';
require_once 'config.inc.php';
/* If access tokens are not available redirect to connect page. */
if (empty($_SESSION['access_token']) || empty($_SESSION['access_token']['oauth_token']) || empty($_SESSION['access_token']['oauth_token_secret'])) {
    header('Location: ./clearsessions.php');
}
/* Get user access tokens out of the session. */
$access_token = $_SESSION['access_token'];
/* Create a MendeleyOauth object with consumer/user tokens. */
$connection = new MendeleyOauth(CONSUMER_KEY, CONSUMER_SECRET, $access_token['oauth_token'], $access_token['oauth_token_secret'], HTTP_PROXY);
$content = '';
// Public methods
$content .= '<h2>Public methods</h2>';
$content .= '<p>Look up reference using DOI</p>';
$doi = '10.1186/2047-217X';
$url = 'http://api.mendeley.com/oapi/documents/details/' . urlencode(urlencode($doi)) . '/?type=doi&consumer_key=CONSUMER_KEY';
$content .= '<h3>' . $url . '</h3>';
$url = str_replace('CONSUMER_KEY', 'cd1634437de8f30a429210b45678647b04c62a4d4', $url);
$content .= '<pre>' . json_format($connection->http($url, 'GET')) . '</pre>';
$url = 'http://api.mendeley.com/oapi/documents/tagged/' . urlencode('phylogeny') . '/?consumer_key=CONSUMER_KEY';
$content .= '<h3>' . $url . '</h3>';
$url = str_replace('CONSUMER_KEY', 'cd1634437de8f30a429210b45678647b04c62a4d4', $url);
$content .= '<pre>' . json_format($connection->http($url, 'GET')) . '</pre>';
/* Include HTML to display on the page */
include 'html.inc';