本文整理汇总了PHP中OAuthUtil::urlencode_rfc3986方法的典型用法代码示例。如果您正苦于以下问题:PHP OAuthUtil::urlencode_rfc3986方法的具体用法?PHP OAuthUtil::urlencode_rfc3986怎么用?PHP OAuthUtil::urlencode_rfc3986使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OAuthUtil
的用法示例。
在下文中一共展示了OAuthUtil::urlencode_rfc3986方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: build_http_body
public static function build_http_body($params)
{
if (!$params) {
return '';
}
// Urlencode both keys and values
$keys = OAuthUtil::urlencode_rfc3986(array_keys($params));
$values = OAuthUtil::urlencode_rfc3986(array_values($params));
$params = array_combine($keys, $values);
// Parameters are sorted by name, using lexicographical byte value ordering.
// Ref: Spec: 9.1.1 (1)
uksort($params, 'strcmp');
$pairs = array();
foreach ($params as $parameter => $value) {
if (is_array($value)) {
// If two or more parameters share the same name, they are sorted by their value
// Ref: Spec: 9.1.1 (1)
// June 12th, 2010 - changed to sort because of issue 164 by hidetaka
sort($value, SORT_STRING);
foreach ($value as $duplicate_value) {
$pairs[] = $parameter . '=' . $duplicate_value;
}
} else {
$pairs[] = $parameter . '=' . $value;
}
}
// For each parameter, the name is separated from the corresponding value by an '=' character (ASCII code 61)
// Each name-value pair is separated by an '&' character (ASCII code 38)
return implode('&', $pairs);
}
示例2: getPostvals
public function getPostvals($force = false)
{
if (opCalendarApiHandler::GET !== $this->method || $force) {
if (!$this->parameters) {
return null;
}
// Urlencode both keys and values
$keys = OAuthUtil::urlencode_rfc3986(array_keys($this->parameters));
$values = OAuthUtil::urlencode_rfc3986(array_values($this->parameters));
$params = array_combine($keys, $values);
// Parameters are sorted by name, using lexicographical byte value ordering.
// Ref: Spec: 9.1.1 (1)
uksort($params, 'strcmp');
$pairs = array();
foreach ($params as $parameter => $value) {
if (is_array($value)) {
// If two or more parameters share the same name, they are sorted by their value
// Ref: Spec: 9.1.1 (1)
natsort($value);
foreach ($value as $duplicate_value) {
$pairs[] = $parameter . '=' . $duplicate_value;
}
} else {
$pairs[] = $parameter . '=' . $value;
}
}
// For each parameter, the name is separated from the corresponding value by an '=' character (ASCII code 61)
// Each name-value pair is separated by an '&' character (ASCII code 38)
return implode('&', $pairs);
}
return null;
}
示例3: build_signature
/**
* oauth_signature is set to the concatenated encoded values of the Consumer Secret and
* Token Secret, separated by a '&' character (ASCII code 38), even if either secret is
* empty. The result MUST be encoded again.
* - Chapter 9.4.1 ("Generating Signatures")
*
* Please note that the second encoding MUST NOT happen in the SignatureMethod, as
* OAuthRequest handles this!
*/
public function build_signature($request, $consumer, $token)
{
$key_parts = array($consumer->secret, $token ? $token->secret : "");
$key_parts = OAuthUtil::urlencode_rfc3986($key_parts);
$key = implode('&', $key_parts);
$request->base_string = $key;
return $key;
}
示例4: build_signature
public function build_signature($request, $consumer, $token)
{
$base_string = $request->get_signature_base_string();
$request->base_string = $base_string;
$key_parts = array($consumer->secret, $token ? $token->secret : "");
$key_parts = OAuthUtil::urlencode_rfc3986($key_parts);
$key = implode('&', $key_parts);
return base64_encode(hash_hmac('sha1', $base_string, $key, true));
}
示例5: api_content
function api_content(&$a)
{
if ($a->cmd == 'api/oauth/authorize') {
/*
* api/oauth/authorize interact with the user. return a standard page
*/
$a->page['template'] = "minimal";
// get consumer/client from request token
try {
$request = OAuthRequest::from_request();
} catch (Exception $e) {
echo "<pre>";
var_dump($e);
killme();
}
if (x($_POST, 'oauth_yes')) {
$app = oauth_get_client($request);
if (is_null($app)) {
return "Invalid request. Unknown token.";
}
$consumer = new OAuthConsumer($app['client_id'], $app['pw'], $app['redirect_uri']);
$verifier = md5($app['secret'] . local_channel());
set_config("oauth", $verifier, local_channel());
if ($consumer->callback_url != null) {
$params = $request->get_parameters();
$glue = "?";
if (strstr($consumer->callback_url, $glue)) {
$glue = "?";
}
goaway($consumer->callback_url . $glue . "oauth_token=" . OAuthUtil::urlencode_rfc3986($params['oauth_token']) . "&oauth_verifier=" . OAuthUtil::urlencode_rfc3986($verifier));
killme();
}
$tpl = get_markup_template("oauth_authorize_done.tpl");
$o = replace_macros($tpl, array('$title' => t('Authorize application connection'), '$info' => t('Return to your app and insert this Securty Code:'), '$code' => $verifier));
return $o;
}
if (!local_channel()) {
//TODO: we need login form to redirect to this page
notice(t('Please login to continue.') . EOL);
return login(false, 'api-login', $request->get_parameters());
}
//FKOAuth1::loginUser(4);
$app = oauth_get_client($request);
if (is_null($app)) {
return "Invalid request. Unknown token.";
}
$tpl = get_markup_template('oauth_authorize.tpl');
$o = replace_macros($tpl, array('$title' => t('Authorize application connection'), '$app' => $app, '$authorize' => t('Do you want to authorize this application to access your posts and contacts, and/or create new posts for you?'), '$yes' => t('Yes'), '$no' => t('No')));
//echo "<pre>"; var_dump($app); killme();
return $o;
}
echo api_call($a);
killme();
}
示例6: build_signature
public function build_signature($request, $consumer, $token)
{
global $OAuth_last_computed_signature;
$OAuth_last_computed_signature = false;
$base_string = $request->get_signature_base_string();
$request->base_string = $base_string;
$key_parts = array($consumer->secret, $token ? $token->secret : "");
$key_parts = OAuthUtil::urlencode_rfc3986($key_parts);
$key = implode('&', $key_parts);
$computed_signature = base64_encode(hash_hmac('sha256', $base_string, $key, true));
$OAuth_last_computed_signature = $computed_signature;
return $computed_signature;
}
示例7: build_signature
public function build_signature($request, $consumer, $token)
{
$sig = array(OAuthUtil::urlencode_rfc3986($consumer->secret));
if ($token) {
array_push($sig, OAuthUtil::urlencode_rfc3986($token->secret));
} else {
array_push($sig, '');
}
$raw = implode("&", $sig);
// for debug purposes
$request->base_string = $raw;
return OAuthUtil::urlencode_rfc3986($raw);
}
示例8: build_signature
public function build_signature($request, $consumer, $token)
{
$base_string = $request->get_signature_base_string();
$base_string = preg_replace_callback("/(%[A-Za-z0-9]{2})/", array($this, "replace_callback"), $base_string);
//convert base string to lowercase
$request->base_string = $base_string;
$key_parts = array($consumer->secret, $token ? $token->secret : "");
$key_parts = OAuthUtil::urlencode_rfc3986($key_parts);
$key = implode('&', $key_parts);
$key = preg_replace_callback("/(%[A-Za-z0-9]{2})/", array($this, "replace_callback"), $key);
//convert to lowercase
return base64_encode(hash_hmac('sha1', $base_string, $key, true));
}
示例9: testUrlencode
public function testUrlencode()
{
// Tests taken from
// http://wiki.oauth.net/TestCases ("Parameter Encoding")
$this->assertEquals('abcABC123', OAuthUtil::urlencode_rfc3986('abcABC123'));
$this->assertEquals('-._~', OAuthUtil::urlencode_rfc3986('-._~'));
$this->assertEquals('%25', OAuthUtil::urlencode_rfc3986('%'));
$this->assertEquals('%2B', OAuthUtil::urlencode_rfc3986('+'));
$this->assertEquals('%0A', OAuthUtil::urlencode_rfc3986("\n"));
$this->assertEquals('%20', OAuthUtil::urlencode_rfc3986(' '));
$this->assertEquals('%7F', OAuthUtil::urlencode_rfc3986(""));
//$this->assertEquals('%C2%80', OAuthUtil::urlencode_rfc3986("\x00\x80"));
//$this->assertEquals('%E3%80%81', OAuthUtil::urlencode_rfc3986("\x30\x01"));
// Last two checks disabled because of lack of UTF-8 support, or lack
// of knowledge from me (morten.fangel) on how to use it properly..
// A few tests to ensure code-coverage
$this->assertEquals('', OAuthUtil::urlencode_rfc3986(NULL));
$this->assertEquals('', OAuthUtil::urlencode_rfc3986(new stdClass()));
}
示例10: access_token
public static function access_token($request)
{
$token = self::$server->fetch_access_token($request);
header('Content-Type: application/x-www-form-urlencoded');
return sprintf('oauth_token=%s&oauth_token_secret=%s', OAuthUtil::urlencode_rfc3986($token->key), OAuthUtil::urlencode_rfc3986($token->secret));
}
示例11: requestAuthorization
/**
* Request authorization
*
* Returns an URL which equals to an authorization request. The end user
* should be redirected to this location to perform authorization.
* The $finish_url should be a local resource which invokes
* OMB_Consumer::finishAuthorization on request.
*
* @param OMB_Profile $profile An OMB_Profile object representing the
* soon-to-be subscribed (i. e. local) user
* @param string $finish_url Target location after successful
* authorization
*
* @access public
*
* @return string An URL representing an authorization request
*/
public function requestAuthorization($profile, $finish_url)
{
if ($this->performLegacyAuthRequest) {
$params = $profile->asParameters('omb_listenee', false);
$params['omb_listener'] = $this->listener_uri;
$params['oauth_callback'] = $finish_url;
$url = $this->prepareAction(OAUTH_ENDPOINT_AUTHORIZE, $params, 'GET')->to_url();
} else {
$params = array('oauth_callback' => $finish_url, 'oauth_token' => $this->token->key, 'omb_version' => OMB_VERSION, 'omb_listener' => $this->listener_uri);
$params = array_merge($profile->asParameters('omb_listenee', false), $params);
/* Build result URL. */
$url = $this->services[OAUTH_ENDPOINT_AUTHORIZE] . (strrpos($url, '?') === false ? '?' : '&');
foreach ($params as $k => $v) {
$url .= OAuthUtil::urlencode_rfc3986($k) . '=' . OAuthUtil::urlencode_rfc3986($v) . '&';
}
}
$this->listenee_uri = $profile->getIdentifierURI();
return $url;
}
示例12: build_http_query
public static function build_http_query($params)
{
if (!$params) {
return '';
}
$keys = OAuthUtil::urlencode_rfc3986(array_keys($params));
$values = OAuthUtil::urlencode_rfc3986(array_values($params));
$params = array_combine($keys, $values);
uksort($params, 'strcmp');
$pairs = array();
foreach ($params as $parameter => $value) {
if (is_array($value)) {
natsort($value);
foreach ($value as $duplicate_value) {
$pairs[] = $parameter . '=' . $duplicate_value;
}
} else {
$pairs[] = $parameter . '=' . $value;
}
}
return implode('&', $pairs);
}
示例13: buildCallbackUrl
function buildCallbackUrl($url, $params)
{
foreach ($params as $k => $v) {
$url = $this->appendQueryVar($url, OAuthUtil::urlencode_rfc3986($k), OAuthUtil::urlencode_rfc3986($v));
}
return $url;
}
示例14: nkConnectLoginUri
/**
* Ta metoda buduje URL przyjmujący żądania logowania użytkownika. Jeśli nie chcesz korzystać ze standardowo oferowanych
* tutaj elementów (->button()) możesz samodzielnie zbudować element logowania używając tej metody jako źródła adresu
* docelowego.
*
* @return string
*/
public function nkConnectLoginUri()
{
return "https://nk.pl/oauth2/login" . "?client_id=" . $this->getConfig()->key . "&response_type=code" . "&redirect_uri=" . OAuthUtil::urlencode_rfc3986($this->redirectUri()) . "&scope=" . implode(',', $this->getConfig()->permissions) . "&state=" . $this->getOtp();
}
示例15: sign
/**
* Signs the request and adds the OAuth signature. This runs all the request
* parameter preparation methos.
*
* @param string $method the HTTP being used. ex POST, GET, HEAD etc
* @param string $url the request URL without query string parameters.
* @param array $params the request parameters as an array of key=value pairs
* @param string $useauth whether to use authentication when making the request.
*/
private function sign($method, $url, $params, $useauth)
{
$this->prepare_method($method);
$this->prepare_url($url);
$this->prepare_params($params);
// we don't sign anything is we're not using auth
if ($useauth) {
$this->prepare_base_string();
$this->prepare_signing_key();
$this->auth_params['oauth_signature'] = OAuthUtil::urlencode_rfc3986(base64_encode(hash_hmac('sha1', $this->base_string, $this->signing_key, true)));
}
$this->prepare_auth_header();
}