コード例 #1
1
 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)));
 }
コード例 #2
0
ファイル: BasicSpec.php プロジェクト: indigophp/scaleway
 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);
 }
コード例 #3
0
ファイル: Basic.php プロジェクト: indigophp/scaleway
 /**
  * {@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);
 }
コード例 #4
0
 /**
  * @param StreamInterface $body
  * @return $this|Request
  */
 public function withBody(StreamInterface $body)
 {
     $this->request = $this->request->withBody($body);
     return $this;
 }
コード例 #5
0
ファイル: Request.php プロジェクト: deepfreeze/zend-diactoros
 public function withBody(StreamInterface $body)
 {
     $new = clone $this;
     $new->request = $this->request->withBody($body);
     return $new;
 }
コード例 #6
0
 /**
  * @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));
 }
コード例 #7
0
 private function getCopyOfRequestWithEmptyBody(RequestInterface $request) : RequestInterface
 {
     $emptyStream = new Stream(fopen('php://temp', 'r+'));
     return $request->withBody($emptyStream);
 }