コード例 #1
0
 /**
  * Handle a request for temporary OAuth credentials
  *
  * Make sure the request is kosher, then emit a set of temporary
  * credentials -- AKA an unauthorized request token.
  *
  * @param array $args array of arguments
  *
  * @return void
  */
 function handle($args)
 {
     parent::handle($args);
     $datastore = new ApiStatusNetOAuthDataStore();
     $server = new OAuthServer($datastore);
     $hmac_method = new OAuthSignatureMethod_HMAC_SHA1();
     $server->add_signature_method($hmac_method);
     try {
         $req = OAuthRequest::from_request();
         // verify callback
         if (!$this->verifyCallback($req->get_parameter('oauth_callback'))) {
             throw new OAuthException("You must provide a valid URL or 'oob' in oauth_callback.", 400);
         }
         // check signature and issue a new request token
         $token = $server->fetch_request_token($req);
         common_log(LOG_INFO, sprintf("API OAuth - Issued request token %s for consumer %s with oauth_callback %s", $token->key, $req->get_parameter('oauth_consumer_key'), "'" . $req->get_parameter('oauth_callback') . "'"));
         // return token to the client
         $this->showRequestToken($token);
     } catch (OAuthException $e) {
         common_log(LOG_WARNING, 'API OAuthException - ' . $e->getMessage());
         // Return 401 for for bad credentials or signature problems,
         // and 400 for missing or unsupported parameters
         $code = $e->getCode();
         $this->clientError($e->getMessage(), empty($code) ? 401 : $code, 'text');
     }
 }
コード例 #2
0
ファイル: oauth.php プロジェクト: unpush/partuza
 public function request_token($params)
 {
     try {
         $server = new OAuthServer($this->oauthDataStore);
         $server->add_signature_method(new OAuthSignatureMethod_HMAC_SHA1());
         $server->add_signature_method(new OAuthSignatureMethod_PLAINTEXT());
         $request = OAuthRequest::from_request();
         $token = $server->fetch_request_token($request);
         if ($token) {
             echo $token->to_string();
         }
     } catch (OAuthException $e) {
         $this->sendServerError(401, $e->getMessage());
     } catch (Exception $e) {
         $this->sendServerError(400, $e->getMessage());
     }
 }
コード例 #3
0
 /**
  * Class handler.
  *
  * @param array $args array of arguments
  *
  * @return void
  */
 function handle($args)
 {
     parent::handle($args);
     $datastore = new ApiStatusNetOAuthDataStore();
     $server = new OAuthServer($datastore);
     $hmac_method = new OAuthSignatureMethod_HMAC_SHA1();
     $server->add_signature_method($hmac_method);
     try {
         $req = OAuthRequest::from_request();
         $token = $server->fetch_request_token($req);
         print $token;
     } catch (OAuthException $e) {
         common_log(LOG_WARNING, 'API OAuthException - ' . $e->getMessage());
         header('HTTP/1.1 401 Unauthorized');
         header('Content-Type: text/html; charset=utf-8');
         print $e->getMessage() . "\n";
     }
 }
コード例 #4
0
ファイル: common.inc.php プロジェクト: genaromendezl/ATutor
<?php

/***********************************************************************/
/* ATutor															   */
/***********************************************************************/
/* Copyright (c) 2002-2010                                             */
/* Inclusive Design Institute	                                       */
/* http://atutor.ca													   */
/*																	   */
/* This program is free software. You can redistribute it and/or	   */
/* modify it under the terms of the GNU General Public License		   */
/* as published by the Free Software Foundation.					   */
/***********************************************************************/
// $Id$
require_once 'OAuth.php';
require_once '../Shindig/ATutorOAuthDataStore';
$oauthDataStore = new ATutorOAuthDataStore();
try {
    $server = new OAuthServer($oauthDataStore);
    $server->add_signature_method(new OAuthSignatureMethod_HMAC_SHA1());
    $server->add_signature_method(new OAuthSignatureMethod_PLAINTEXT());
    $request = OAuthRequest::from_request();
    $token = $server->fetch_request_token($request);
    if ($token) {
        echo $token->to_string();
    }
} catch (OAuthException $e) {
    echo $e->getMessage();
} catch (Exception $e) {
    echo $e->getMessage();
}
コード例 #5
0
ファイル: omb.php プロジェクト: Br3nda/openmicroblogger
function request_token(&$vars)
{
    extract($vars);
    if (!(environment('openid_version') > 1) || (!$db->has_table('oauth_consumers') || !$db->has_table('oauth_tokens'))) {
        $db->create_openid_tables();
    }
    wp_plugin_include(array('wp-oauth'));
    $consumerkey = $db->escape_string(urldecode($_POST['oauth_consumer_key']));
    $consumer_result = $db->get_result("SELECT consumer_key FROM oauth_consumers WHERE consumer_key = '{$consumerkey}'");
    if (!$db->num_rows($consumer_result) > 0) {
        $result = $db->get_result("INSERT INTO oauth_consumers (consumer_key, secret, description) VALUES ('{$consumerkey}', '', 'Unidentified Consumer')");
    }
    $store = new OAuthWordpressStore();
    $server = new OAuthServer($store);
    $sha1_method = new OAuthSignatureMethod_HMAC_SHA1();
    $plaintext_method = new OAuthSignatureMethod_PLAINTEXT();
    $server->add_signature_method($sha1_method);
    $server->add_signature_method($plaintext_method);
    $params = array();
    foreach ($_POST as $key => $val) {
        if (!($key == 'request_token')) {
            $params[$key] = $val;
        }
    }
    $req = OAuthRequest::from_request();
    $token = $server->fetch_request_token($req);
    header('Status: 200 OK');
    print $token->to_string() . '&xoauth_token_expires=' . urlencode($store->token_expires($token));
    exit;
}