本文整理汇总了PHP中OAuthUtil::parse_parameters方法的典型用法代码示例。如果您正苦于以下问题:PHP OAuthUtil::parse_parameters方法的具体用法?PHP OAuthUtil::parse_parameters怎么用?PHP OAuthUtil::parse_parameters使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OAuthUtil
的用法示例。
在下文中一共展示了OAuthUtil::parse_parameters方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: from_request
/**
* attempt to build up a request from what was passed to the server
*/
public static function from_request($http_method = NULL, $http_url = NULL, $parameters = NULL)
{
$scheme = !isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != "on" ? 'http' : 'https';
$http_url = $http_url ? $http_url : $scheme . '://' . $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT'] . $_SERVER['REQUEST_URI'];
$http_method = $http_method ? $http_method : $_SERVER['REQUEST_METHOD'];
// We weren't handed any parameters, so let's find the ones relevant to
// this request.
// If you run XML-RPC or similar you should use this to provide your own
// parsed parameter-list
if (!$parameters) {
// Find request headers
$request_headers = OAuthUtil::get_headers();
// Parse the query-string to find GET parameters
$parameters = OAuthUtil::parse_parameters($_SERVER['QUERY_STRING']);
// It's a POST request of the proper content-type, so parse POST
// parameters and add those overriding any duplicates from GET
if ($http_method == "POST" && isset($request_headers['Content-Type']) && strstr($request_headers['Content-Type'], 'application/x-www-form-urlencoded')) {
$post_data = OAuthUtil::parse_parameters(file_get_contents(self::$POST_INPUT));
$parameters = array_merge($parameters, $post_data);
}
// We have a Authorization-header with OAuth data. Parse the header
// and add those overriding any duplicates from GET or POST
if (isset($request_headers['Authorization']) && substr($request_headers['Authorization'], 0, 6) == 'OAuth ') {
$header_parameters = OAuthUtil::split_header($request_headers['Authorization']);
$parameters = array_merge($parameters, $header_parameters);
}
}
return new OAuthRequest($http_method, $http_url, $parameters);
}
示例2: getAccessToken
/**
* (non-PHPdoc)
* @see plugins/sfDoctrineOAuthPlugin/lib/sfOAuth::getAccessToken()
*/
public function getAccessToken($verifier, $parameters = array())
{
$url = $this->getAccessTokenUrl();
$this->setAccessParameter('client_id', $this->getKey());
$this->setAccessParameter('client_secret', $this->getSecret());
$this->setAccessParameter('redirect_uri', $this->getCallback());
$this->setAccessParameter('code', $verifier);
$this->addAccessParameters($parameters);
$params = $this->call($url, $this->getAccessParameters(), 'GET');
$params = OAuthUtil::parse_parameters($params);
$access_token = isset($params['access_token']) ? $params['access_token'] : null;
if (is_null($access_token) && $this->getLogger()) {
$error = sprintf('{OAuth} access token failed - %s returns %s', $this->getName(), print_r($params, true));
$this->getLogger()->err($error);
} elseif ($this->getLogger()) {
$message = sprintf('{OAuth} %s return %s', $this->getName(), print_r($params, true));
$this->getLogger()->info($message);
}
$token = new Token();
$token->setTokenKey($access_token);
$token->setName($this->getName());
$token->setStatus(Token::STATUS_ACCESS);
$token->setOAuthVersion($this->getVersion());
unset($params['access_token']);
if (count($params) > 0) {
$token->setParams($params);
}
$this->setExpire($token);
$this->setToken($token);
// get identifier maybe need the access token
$token->setIdentifier($this->getIdentifier());
$this->setToken($token);
return $token;
}
示例3: getAccessToken
public function getAccessToken($consumerName, $accessTokenURL, $requestToken, $httpMethod = 'POST', $parameters = array())
{
$this->url = $accessTokenURL;
$queryStringParams = OAuthUtil::parse_parameters($_SERVER['QUERY_STRING']);
$parameters['oauth_verifier'] = $queryStringParams['oauth_verifier'];
$request = $this->createRequest($consumerName, $httpMethod, $accessTokenURL, $requestToken, $parameters);
return $this->doRequest($request);
}
示例4: __construct
function __construct($http_method, $http_url, $parameters = NULL)
{
$parameters = $parameters ? $parameters : array();
$parameters = array_merge(OAuthUtil::parse_parameters(parse_url($http_url, PHP_URL_QUERY)), $parameters);
$this->parameters = $parameters;
$this->http_method = $http_method;
$this->http_url = $http_url;
}
示例5: testParseParameter
public function testParseParameter()
{
// Tests taken from
// http://wiki.oauth.net/TestCases ("Normalize Request Parameters")
$this->assertEquals(array('name' => ''), OAuthUtil::parse_parameters('name'));
$this->assertEquals(array('a' => 'b'), OAuthUtil::parse_parameters('a=b'));
$this->assertEquals(array('a' => 'b', 'c' => 'd'), OAuthUtil::parse_parameters('a=b&c=d'));
$this->assertEquals(array('a' => array('x!y', 'x y')), OAuthUtil::parse_parameters('a=x!y&a=x+y'));
$this->assertEquals(array('x!y' => 'a', 'x' => 'a'), OAuthUtil::parse_parameters('x!y=a&x=a'));
}
示例6: get_access_token
function get_access_token($username, $password)
{
$parameters = array();
$parameters['x_auth_username'] = $username;
$parameters['x_auth_password'] = $password;
$parameters['x_auth_mode'] = 'client_auth';
$request = $this->oAuthRequest($this->host . "oauth/access_token", 'POST', $parameters);
$token = OAuthUtil::parse_parameters($request);
$this->token = new OAuthConsumer($token['oauth_token'], $token['oauth_token_secret']);
return $token;
}
示例7: getAccessToken
public function getAccessToken($verifier = false)
{
$params = array();
if (!empty($verifier)) {
$params['oauth_verifier'] = $verifier;
}
$response = $this->_request($this->_accessTokenUrl, 'GET', $params);
$token = OAuthUtil::parse_parameters($response);
$this->_token = new OAuthConsumer($token['oauth_token'], $token['oauth_token_secret']);
return $token;
}
示例8: getRequestToken
/**
* gets the request token for the first time
*/
function getRequestToken($oauth_callback = NULL)
{
$params = array();
if (!empty($oauth_callback)) {
$params['oauth_callback'] = $oauth_callback;
}
$request = $this->makeRequest($this->requestTokenURL, false, $params);
$token = OAuthUtil::parse_parameters($request);
$this->token = new OAuthConsumer($token['oauth_token'], $token['oauth_token_secret']);
return $token;
}
示例9: getAccessToken
function getAccessToken($oauth_verifier = FALSE)
{
$parameters = array();
if (!empty($oauth_verifier)) {
$parameters['oauth_verifier'] = $oauth_verifier;
}
$request = $this->oAuthRequest($this->accessTokenURL(), 'GET', $parameters);
$token = OAuthUtil::parse_parameters($request);
$this->token = new OAuthConsumer($token['oauth_token'], $token['oauth_token_secret']);
return $token;
}
示例10: requestToken
function requestToken($callback = null)
{
$parameters = array('scope' => 'read_public');
if ($callback) {
$this->redirect_uri = $parameters['oauth_callback'] = $callback;
}
$request = $this->signedRequest($this->request_token_url, $this->request_token_method, $parameters);
$token = OAuthUtil::parse_parameters($request);
$this->token = new OAuthConsumer($token['oauth_token'], $token['oauth_token_secret']);
return $token;
}
示例11: from_consumer_and_token
/**
* pretty much a helper function to set up the request
*/
public static function from_consumer_and_token($consumer, $token, $http_method, $http_url, $parameters = NULL)
{
@$parameters or $parameters = array();
$defaults = array("oauth_version" => OAuthRequest::$version, "oauth_nonce" => OAuthRequest::generate_nonce(), "oauth_timestamp" => OAuthRequest::generate_timestamp(), "oauth_consumer_key" => $consumer->key);
if ($token) {
$defaults['oauth_token'] = $token->key;
}
$parameters = array_merge($defaults, $parameters);
// Parse the query-string to find and add GET parameters
$parts = parse_url($http_url);
if (isset($parts['query'])) {
$qparms = OAuthUtil::parse_parameters($parts['query']);
$parameters = array_merge($qparms, $parameters);
}
return new OAuthRequest($http_method, $http_url, $parameters);
}
示例12: _extract_token
/**
* Extract token data from a MMI_Curl_Response object and create an
* OAuthToken object.
*
* @param MMI_Curl_Response the response object
* @return OAuthToken
*/
protected function _extract_token($response)
{
if (!$response instanceof MMI_Curl_Response) {
return NULL;
}
$token = NULL;
if (intval($response->http_status_code()) === 200) {
$body = $response->body();
if (!empty($body)) {
$parms = OAuthUtil::parse_parameters($body);
$oauth_token = Arr::get($parms, 'oauth_token');
$oauth_token_secret = Arr::get($parms, 'oauth_token_secret');
if (!empty($oauth_token) and !empty($oauth_token_secret)) {
$token = new OAuthToken($oauth_token, $oauth_token_secret);
unset($parms['oauth_token'], $parms['oauth_token_secret']);
$token->attributes = $parms;
}
}
}
return $token;
}
示例13: getMyUrl
private function getMyUrl()
{
$server_data = $this->getHttpRequest()->getServerData();
$url = true === isset($server_data["HTTPS"]) && 'on' == $server_data["HTTPS"] ? "https://" : "http://";
$url .= $server_data['HTTP_HOST'] . parse_url($server_data['REQUEST_URI'], PHP_URL_PATH);
$params = parse_url($server_data['REQUEST_URI'], PHP_URL_QUERY);
$strip = array('nkconnect_state', 'code', 'state', 'error', 'error_description');
if ($params) {
$p = array();
foreach (OAuthUtil::parse_parameters($params) as $k => $v) {
if (false === in_array($k, $strip)) {
$p[$k] = $v;
}
}
if (0 != count($p)) {
$url .= '?' . OAuthUtil::build_http_query($p);
}
}
return $url;
}
示例14: getXAuthToken
/**
* One time exchange of username and password for access token and secret.
*
* @returns ["oauth_token" => "the-access-token",
* "oauth_token_secret" => "the-access-secret",
* "user_id" => "9436992",
* "screen_name" => "abraham",
* "x_auth_expires" => "0"]
* @throws Exception if the OAuth request fails
*/
function getXAuthToken($username, $password)
{
$parameters = array('x_auth_username' => $username, 'x_auth_password' => $password, 'x_auth_mode' => 'client_auth');
$request = $this->oAuthRequest($this->getUrl('access_token'), 'POST', $parameters);
$token = OAuthUtil::parse_parameters($request);
if (empty($token['oauth_token']) || empty($token['oauth_token_secret'])) {
throw new \Exception('OAuth request failed.');
}
$this->token = new OAuthConsumer($token['oauth_token'], $token['oauth_token_secret']);
return $token;
}
示例15: base_connectData_handler
/**
*
*
* @param Gdn_Controller $Sender
* @param array $Args
*/
public function base_connectData_handler($Sender, $Args)
{
if (val(0, $Args) != 'twitter') {
return;
}
$Form = $Sender->Form;
//new Gdn_Form();
$RequestToken = val('oauth_token', $_GET);
$AccessToken = $Form->getFormValue('AccessToken');
if ($AccessToken) {
$AccessToken = $this->getOAuthToken($AccessToken);
$this->accessToken($AccessToken);
}
// Get the access token.
if ($RequestToken && !$AccessToken) {
// Get the request secret.
$RequestToken = $this->getOAuthToken($RequestToken);
$Consumer = new OAuthConsumer(c('Plugins.Twitter.ConsumerKey'), c('Plugins.Twitter.Secret'));
$Url = 'https://api.twitter.com/oauth/access_token';
$Params = array('oauth_verifier' => val('oauth_verifier', $_GET));
$Request = OAuthRequest::from_consumer_and_token($Consumer, $RequestToken, 'POST', $Url, $Params);
$SignatureMethod = new OAuthSignatureMethod_HMAC_SHA1();
$Request->sign_request($SignatureMethod, $Consumer, $RequestToken);
$Post = $Request->to_postdata();
$Curl = $this->_Curl($Request);
$Response = curl_exec($Curl);
if ($Response === false) {
$Response = curl_error($Curl);
}
$HttpCode = curl_getinfo($Curl, CURLINFO_HTTP_CODE);
curl_close($Curl);
if ($HttpCode == '200') {
$Data = OAuthUtil::parse_parameters($Response);
$AccessToken = new OAuthToken(val('oauth_token', $Data), val('oauth_token_secret', $Data));
// Save the access token to the database.
$this->setOAuthToken($AccessToken->key, $AccessToken->secret, 'access');
$this->accessToken($AccessToken->key, $AccessToken->secret);
// Delete the request token.
$this->deleteOAuthToken($RequestToken);
} else {
// There was some sort of error.
throw new Exception('There was an error authenticating with twitter.', 400);
}
$NewToken = true;
}
// Get the profile.
try {
$Profile = $this->getProfile($AccessToken);
} catch (Exception $Ex) {
if (!isset($NewToken)) {
// There was an error getting the profile, which probably means the saved access token is no longer valid. Try and reauthorize.
if ($Sender->deliveryType() == DELIVERY_TYPE_ALL) {
redirect($this->_AuthorizeHref());
} else {
$Sender->setHeader('Content-type', 'application/json');
$Sender->deliveryMethod(DELIVERY_METHOD_JSON);
$Sender->RedirectUrl = $this->_authorizeHref();
}
} else {
throw $Ex;
}
}
$ID = val('id', $Profile);
$Form->setFormValue('UniqueID', $ID);
$Form->setFormValue('Provider', self::ProviderKey);
$Form->setFormValue('ProviderName', 'Twitter');
$Form->setValue('ConnectName', val('screen_name', $Profile));
$Form->setFormValue('Name', val('screen_name', $Profile));
$Form->setFormValue('FullName', val('name', $Profile));
$Form->setFormValue('Photo', val('profile_image_url_https', $Profile));
$Form->addHidden('AccessToken', $AccessToken->key);
// Save some original data in the attributes of the connection for later API calls.
$Attributes = array(self::ProviderKey => array('AccessToken' => array($AccessToken->key, $AccessToken->secret), 'Profile' => $Profile));
$Form->setFormValue('Attributes', $Attributes);
$Sender->setData('Verified', true);
}