Exemple #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    OAuth1::urlencode
  */
 public function key(OAuth_Consumer $consumer, OAuth_Token $token = NULL)
 {
     $key = OAuth1::urlencode($consumer->secret) . '&';
     if ($token) {
         $key .= OAuth1::urlencode($token->secret);
     }
     return $key;
 }
Exemple #2
0
 /**
  * Convert the request parameters into an `Authorization` header.
  *
  *     $header = $request->as_header();
  *
  * [!!] 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 as_header()
 {
     $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[] = OAuth1::urlencode($name) . '="' . OAuth1::urlencode($value) . '"';
         }
     }
     return 'OAuth ' . implode(', ', $header);
 }
Exemple #3
0
 /**
  * Normalize all request parameters into a string.
  *
  *     $query = OAuth1::normalize_params($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    OAuth1::urlencode
  */
 public static function normalize_params(array $params = NULL)
 {
     if (!$params) {
         // Nothing to do
         return '';
     }
     // Encode the parameter keys and values
     $keys = OAuth1::urlencode(array_keys($params));
     $values = OAuth1::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);
 }