Пример #1
0
 /**
  * Get a signing key from a consumer and token.
  *
  *     $key = $signature->key($consumer, $token);
  *
  * [!!] This method implements the signing key of [OAuth 1.0 Spec 9](http://oauth.net/core/1.0/#rfc.section.9).
  *
  * @param   Consumer  consumer
  * @param   Token     token
  * @return string
  * @uses    OAuth::urlencode
  */
 public function key(Consumer $consumer, Token $token = null)
 {
     $key = OAuth::urlencode($consumer->secret) . '&';
     if ($token) {
         $key .= OAuth::urlencode($token->secret);
     }
     return $key;
 }
Пример #2
0
 /**
  * Normalize all request parameters into a string.
  *
  *     $query = OAuth::normalizeParams($params);
  *
  * [!!] This method implements [OAuth 1.0 Spec 9.1.1](http://oauth.net/core/1.0/#rfc.section.9.1.1).
  *
  * @param   array   request parameters
  * @return string
  * @uses    OAuth::urlencode
  */
 public static function normalizeParams(array $params = null)
 {
     if (!$params) {
         // Nothing to do
         return '';
     }
     // Encode the parameter keys and values
     $keys = OAuth::urlencode(array_keys($params));
     $values = OAuth::urlencode(array_values($params));
     // Recombine the parameters
     $params = array_combine($keys, $values);
     // OAuth Spec 9.1.1 (1)
     // "Parameters are sorted by name, using lexicographical byte value ordering."
     uksort($params, 'strcmp');
     // Create a new query string
     $query = array();
     foreach ($params as $name => $value) {
         if (is_array($value)) {
             // OAuth Spec 9.1.1 (1)
             // "If two or more parameters share the same name, they are sorted by their value."
             $value = natsort($value);
             foreach ($value as $duplicate) {
                 $query[] = $name . '=' . $duplicate;
             }
         } else {
             $query[] = $name . '=' . $value;
         }
     }
     return implode('&', $query);
 }
Пример #3
0
 /**
  * Convert the request parameters into an `Authorization` header.
  *
  *     $header = $request->asHeader();
  *
  * [!!] This method implements [OAuth 1.0 Spec 5.4.1](http://oauth.net/core/1.0/#rfc.section.5.4.1).
  *
  * @return string
  */
 public function asHeader()
 {
     $header = array();
     foreach ($this->params as $name => $value) {
         if (strpos($name, 'oauth_') === 0) {
             // OAuth Spec 5.4.1
             // "Parameter names and values are encoded per Parameter Encoding [RFC 3986]."
             $header[] = OAuth::urlencode($name) . '="' . OAuth::urlencode($value) . '"';
         }
     }
     return 'OAuth ' . implode(', ', $header);
 }