コード例 #1
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);
     $atok = $app = null;
     // XXX: Insist that oauth_token and oauth_verifier be populated?
     // Spec doesn't say they MUST be.
     try {
         $req = OAuthRequest::from_request();
         $this->reqToken = $req->get_parameter('oauth_token');
         $this->verifier = $req->get_parameter('oauth_verifier');
         $app = $datastore->getAppByRequestToken($this->reqToken);
         $atok = $server->fetch_access_token($req);
     } catch (Exception $e) {
         common_log(LOG_WARNING, 'API OAuthException - ' . $e->getMessage());
         common_debug(var_export($req, true));
         $code = $e->getCode();
         $this->clientError($e->getMessage(), empty($code) ? 401 : $code, 'text');
         return;
     }
     if (empty($atok)) {
         // Token exchange failed -- log it
         $msg = sprintf('API OAuth - Failure exchanging OAuth request token for access token, ' . 'request token = %s, verifier = %s', $this->reqToken, $this->verifier);
         common_log(LOG_WARNING, $msg);
         // TRANS: Client error given from the OAuth API when the request token or verifier is invalid.
         $this->clientError(_('Invalid request token or verifier.'), 400, 'text');
     } else {
         common_log(LOG_INFO, sprintf("Issued access token '%s' for application %d (%s).", $atok->key, $app->id, $app->name));
         $this->showAccessToken($atok);
     }
 }
コード例 #2
0
ファイル: oauth.php プロジェクト: vuxuandung/Partuza-bundle
 public function access_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_access_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);
     $atok = null;
     try {
         $req = OAuthRequest::from_request();
         $atok = $server->fetch_access_token($req);
     } catch (OAuthException $e) {
         common_log(LOG_WARNING, 'API OAuthException - ' . $e->getMessage());
         common_debug(var_export($req, true));
         $this->outputError($e->getMessage());
         return;
     }
     if (empty($atok)) {
         common_debug('couldn\'t get access token.');
         print "Token exchange failed. Has the request token been authorized?\n";
     } else {
         print $atok;
     }
 }
コード例 #4
0
ファイル: access_token.php プロジェクト: genaromendezl/ATutor
/***********************************************************************/
/* 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.php';
$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_access_token($request);
    if ($token) {
        echo $token->to_string();
    }
    echo $token;
} catch (OAuthException $e) {
    echo $e->getMessage();
} catch (Exception $e) {
    echo $e->getMessage();
}
コード例 #5
0
ファイル: omb.php プロジェクト: Br3nda/openmicroblogger
function access_token(&$vars)
{
    extract($vars);
    wp_plugin_include(array('wp-oauth'));
    $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);
    $req = OAuthRequest::from_request();
    $token = $server->fetch_access_token($req);
    header('Status: 200 OK');
    print $token->to_string() . '&xoauth_token_expires=' . urlencode($store->token_expires($token));
    exit;
}