public static function decodeHeaderEncodedArray($headerValue){ $valuesArr = array(); $pairs = array(); $name = ''; $value = ''; if(is_string($headerValue)){ $valuesArr = explode(',',$headerValue); foreach($valuesArr as $pair){ if(strpos($pair,'=')){ //this param has a key value pair $pair = trim($pair); list($name, $value) = explode('=', $param, 2); }else{ //this is an empty param and only has a name $name = $pair; $value = ''; } //lets push it to the array if it has a name if(!empty($name)){ //we may need to validate the $name, not all returnable chars may be valid $name = OAuthUtil::urldecodeRFC3986($name); $value = OAuthUtil::urldecodeRFC3986($value); //we should be able to set value to an empty string '' $pairs[$name] = $value; } }//end foreach return $pairs;//returns array } return null;//was unable to parse }
public static function decodeForm($form) { $parameters = array(); $explodedForm = explode("&", $form); foreach ($explodedForm as $params) { $value = explode("=", $params); if (!empty($value[0]) && !empty($value[1])) { $parameters[OAuthUtil::urldecodeRFC3986($value[0])] = OAuthUtil::urldecodeRFC3986($value[1]); } } return $parameters; }
/** * Obtains a request token from the specified provider. * * @param apiCache $cache cache class to use (file,apc,memcache,mysql) */ public function obtainRequestToken($callbackUrl, $uid) { $callbackParams = (strpos($_SERVER['REQUEST_URI'], '?') !== false ? '&' : '?') . 'uid=' . urlencode($uid); $ret = $this->requestRequestToken($callbackUrl . $callbackParams); $matches = array(); preg_match('/oauth_token=(.*)&oauth_token_secret=(.*)&oauth_callback_confirmed=(.*)/', $ret, $matches); if (!is_array($matches) || count($matches) != 4) { throw new apiAuthException("Error retrieving request key ({$ret})"); } return new OAuthToken(OAuthUtil::urldecodeRFC3986($matches[1]), OAuthUtil::urldecodeRFC3986($matches[2])); }
/** * Get honest-to-goodness user data. */ private function fetchData() { try { $msgParams = OAuthUtil::isFormEncoded($this->realRequest->getContentType()) ? OAuthUtil::urldecodeRFC3986($this->realRequest->getPostBody()) : array(); $method = $this->realRequest->getMethod(); $msgParams[self::$XOAUTH_APP_URL] = $this->authToken->getAppUrl(); // Build and sign the message. $oauthRequest = $this->newRequestMessageMethod($method, $this->realRequest->getUrl(), $msgParams); $rcr = $this->createRemoteContentRequest($this->filterOAuthParams($oauthRequest), $this->realRequest->getMethod(), $this->realRequest->getUrl(), $this->realRequest->getHeaders(), $this->realRequest->getContentType(), $this->realRequest->getPostBody(), $this->realRequest->getOptions()); $content = $this->getNextFetcher()->fetchRequest($rcr); //TODO is there a better way to detect an SP error? $statusCode = $content->getHttpCode(); if ($statusCode >= 400 && $statusCode < 500) { $message = $this->parseAuthHeader(null, $content); if ($message->get_parameter(OAuth::$OAUTH_PROBLEM) != null) { throw new OAuthProtocolException($message); } } // Track metadata on the response $this->addResponseMetadata(); return $content; } catch (Exception $e) { throw new GadgetException("INTERNAL SERVER ERROR: " . $e); } }