示例#1
0
 /**
  * Signs the Request so it can be dispatched.
  *
  * @param  Request $request The Request to Sign
  * @return $this
  */
 public function signRequest(Request $request)
 {
     if ($request->isSigned()) {
         return $this;
     }
     $query = $request->getQuery();
     $query['auth_key'] = $this->credentials->getAuthKey();
     $query['auth_timestamp'] = time();
     $query['auth_version'] = '1.0';
     if (!is_null($request->getBody())) {
         $query['body_md5'] = md5($request->getBody());
     }
     ksort($query);
     $queryString = urldecode(http_build_query(array_change_key_case($query, CASE_LOWER)));
     $stringToSign = $request->getMethod() . "\n" . $request->getUri() . "\n" . $queryString;
     $query['auth_signature'] = hash_hmac('sha256', $stringToSign, $this->credentials->getAuthSecret());
     $request->setQuery($query);
     $request->setSigned(true);
     return $this;
 }