/**
     * {@inheritdoc}
     * @param \Zeflasher\OAuth\Provider\OAuthRequest $request
     * @param string $consumer_secret
     * @param string $token_secret
     * @return string
     */
    public function build_signature($request, $consumer_secret, $token_secret = '')
    {
        $base_string = $request->get_signature_base_string();
        $request->base_string = $base_string;

        $key_parts = array( $consumer_secret, $token_secret );

        $key_parts = \Zeflasher\OAuth\OAuthUtil::urlencode_rfc3986($key_parts);
        $key = implode('&', $key_parts);

        return base64_encode(hash_hmac('sha1', $base_string, $key, true));
    }
Exemplo n.º 2
0
    /**
     * Builds the Authorization header
     *
     * @param string|null $realm
     * @return string
     * @throws \Zeflasher\OAuth\OAuthException
     */
    public function to_header($realm=null)
    {
        $first = true;
        if($realm)
        {
            $out = 'Authorization: OAuth realm="' . \Zeflasher\OAuth\OAuthUtil::urlencode_rfc3986($realm) . '"';
            $first = false;
        }
        else
        {
            $out = 'Authorization: OAuth';
        }

        foreach ($this->_parameters as $k => $v)
        {
            if (substr($k, 0, 5) != "oauth")
            {
                continue;
            }
            if (is_array($v))
            {
                throw new \Zeflasher\OAuth\OAuthException('Arrays not supported in headers');
            }
            $out .= ($first) ? ' ' : ',';
            $out .= \Zeflasher\OAuth\OAuthUtil::urlencode_rfc3986($k) . '="'
                . \Zeflasher\OAuth\OAuthUtil::urlencode_rfc3986($v)
                . '"';
            $first = false;
        }
        return $out;
    }
Exemplo n.º 3
0
    /**
     * The body request parameters (excluded oauth), sorted and concatenated into a normalized string.
     * @return string
     */
    public function get_query_parameters()
    {
        // Grab all parameters
        $params = array_merge($this->_parameters);

        foreach ($params as $key => $image)
        {
            if (preg_match("/^oauth_.*/", $key, $matches))
            {
                unset($params[$key]);
            }
        }

        return \Zeflasher\OAuth\OAuthUtil::build_http_query($params);
    }
Exemplo n.º 4
0
    /**
     * Get a string with all the parameters alphabetically sorted and URL encoded.
     * @return string
     */
    public function getSortedEncodedParametersAsString()
    {
        $params = getSortedParameters();
        $paramsCount     = count($params);
        $encodedString   = '';

        for ($i = 0; $i < $paramsCount; $i++)
        {
            $param = $params[$i];
            if ($param->key != \Zeflasher\OAuth\OAuthConstants::OAUTH_CLIENT_SIGNATURE)
            {
                $encodedString .= \Zeflasher\OAuth\OAuthUtil::urlencode_rfc3986($param->key);
                $encodedString .= '=';
                $encodedString .= \Zeflasher\OAuth\OAuthUtil::urlencode_rfc3986($param->value);
                $encodedString .= '&';
            }
        }

        // return them like a querystring
        return substr($encodedString, 0, strlen($encodedString)-1);
    }
Exemplo n.º 5
0
 /**
  * Similar to parse_str. Returns false if the query string or URL is empty. Because we're not parsing to
  * variables but to array key entries, this function will handle ?[]=1&[]=2 "correctly."
  *
  * @param array $tokens A query string or URL
  * @return array Similar to the $_GET formatting that PHP does automagically.
  */
 public static function parse_query_string($tokens)
 {
     $urlVars = array();
     foreach ($tokens as $token => $value) {
         if (preg_match('/^([^\[]*)(\[.*\])$/', $token, $matches)) {
             \Zeflasher\OAuth\OAuthUtil::parse_query_string_array($urlVars, $matches[1], $matches[2], $value);
         } else {
             $urlVars[urldecode($token)] = urldecode($value);
         }
     }
     return $urlVars;
 }