public function signRequest(RequestInterface $request, CredentialsInterface $credentials)
 {
     $params = Psr7\parse_query($request->getBody());
     $params['Timestamp'] = gmdate('c');
     $params['SignatureVersion'] = '2';
     $params['SignatureMethod'] = 'HmacSHA256';
     $params['AWSAccessKeyId'] = $credentials->getAccessKeyId();
     if ($token = $credentials->getSecurityToken()) {
         $params['SecurityToken'] = $token;
     }
     // build string to sign
     $sign = $request->getMethod() . "\n" . $request->getHeaderLine('Host') . "\n" . '/' . "\n" . $this->getCanonicalizedParameterString($params);
     $params['Signature'] = base64_encode(hash_hmac('sha256', $sign, $credentials->getSecretKey(), true));
     return $request->withBody(Psr7\stream_for(http_build_query($params)));
 }
Example #2
0
 function it_authenticates_a_request(RequestInterface $request, RequestInterface $newRequest, StreamableInterface $body)
 {
     $body->__toString()->willReturn('{}');
     $body->rewind()->shouldBeCalled();
     $body->isSeekable()->willReturn(true);
     $body->isWritable()->willReturn(true);
     $body->write(json_encode(['email' => '*****@*****.**', 'password' => 'secret']))->shouldBeCalled();
     $request->getBody()->willReturn($body);
     $request->withBody(Argument::type('Psr\\Http\\Message\\StreamableInterface'))->willReturn($newRequest);
     $request = $this->authenticateRequest($request);
     $request->shouldBe($newRequest);
 }
Example #3
0
 /**
  * {@inheritdoc}
  */
 public function authenticateRequest(RequestInterface $request)
 {
     $requestBody = $request->getBody();
     $this->ensureBodyRewritable($requestBody);
     $body = (string) $requestBody;
     $body = json_decode($body, true);
     $this->ensureJsonDecodedCorrectly();
     $body['email'] = $this->email;
     $body['password'] = $this->password;
     $requestBody->rewind();
     $requestBody->write(json_encode($body));
     return $request->withBody($requestBody);
 }
 /**
  * @param StreamInterface $body
  * @return $this|Request
  */
 public function withBody(StreamInterface $body)
 {
     $this->request = $this->request->withBody($body);
     return $this;
 }
Example #5
0
 public function withBody(StreamInterface $body)
 {
     $new = clone $this;
     $new->request = $this->request->withBody($body);
     return $new;
 }
 /**
  * @param string $body The raw request body.
  *
  * @return void
  * @author Mario Mueller
  */
 public function setBody($body)
 {
     $this->guzzleRequest = $this->guzzleRequest->withBody(\GuzzleHttp\Psr7\stream_for($body));
 }
 private function getCopyOfRequestWithEmptyBody(RequestInterface $request) : RequestInterface
 {
     $emptyStream = new Stream(fopen('php://temp', 'r+'));
     return $request->withBody($emptyStream);
 }