//var_dump($privkey);
$csrt = openssl_csr_new($dn, $privkey);
//var_dump($csrt);
openssl_csr_export($csrt, $csrout);
$conscsr = pem2der($csrout);
//var_dump($conscsr);
$privrsakey = file_get_contents($pemfile);
session_start();
// In state=1 the next request should include an oauth_token.
// If it doesn't go back to 0
if (!isset($_GET['oauth_token']) && $_SESSION['state'] == 1) {
    $_SESSION['state'] = 0;
}
try {
    $oauth = new OAuth($conskey, '', OAUTH_SIG_METHOD_RSASHA1, OAUTH_AUTH_TYPE_URI);
    $oauth->setRSACertificate(file_get_contents($pkeyfile));
    $oauth->enableDebug();
    file_put_contents('php://stderr', print_r($oauth->debugInfo, TRUE));
    if (!isset($_GET['oauth_token']) && !$_SESSION['state']) {
        $oauth->fetch($req_url, array("oauth_callback" => $callback_url, "certreq" => $conscsr));
        parse_str($oauth->getLastResponse(), $request_token_info);
        //var_dump($request_token_info);
        $_SESSION['secret'] = $request_token_info['oauth_token_secret'];
        $_SESSION['state'] = 1;
        header('Location: ' . $auth_url . '?oauth_token=' . $request_token_info['oauth_token']);
        file_put_contents('php://stderr', print_r($oauth->debugInfo, TRUE));
        exit;
    } else {
        if ($_SESSION['state'] == 1) {
            $oauth->setToken($_GET['oauth_token'], $_SESSION['secret']);
            $access_token_info = $oauth->getAccessToken($acc_url);
Пример #2
0
<?php

require 'server.inc';
$x = new OAuth('1234', '', OAUTH_SIG_METHOD_RSASHA1);
$x->setRequestEngine(OAUTH_REQENGINE_STREAMS);
$x->setTimestamp(12345);
$x->setNonce('testing');
$x->setRSACertificate(file_get_contents(dirname(__FILE__) . '/test.pem'));
$port = random_free_port();
$pid = http_server("tcp://127.0.0.1:{$port}", array("HTTP/1.0 200 OK\r\nContent-Type: text/plain\r\nContent-Length: 40\r\n\r\noauth_token=1234&oauth_token_secret=4567"), $output);
$x->setAuthType(OAUTH_AUTH_TYPE_URI);
var_dump($x->getRequestToken("http://127.0.0.1:{$port}/test"));
fseek($output, 0, SEEK_SET);
var_dump(stream_get_contents($output));
http_server_kill($pid);