本文整理汇总了PHP中OAuthServer::fetch_access_token方法的典型用法代码示例。如果您正苦于以下问题:PHP OAuthServer::fetch_access_token方法的具体用法?PHP OAuthServer::fetch_access_token怎么用?PHP OAuthServer::fetch_access_token使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OAuthServer
的用法示例。
在下文中一共展示了OAuthServer::fetch_access_token方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handle
/**
* 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: access_token
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: handle
/**
* 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: ATutorOAuthDataStore
/***********************************************************************/
/* 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: access_token
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;
}