createRequest() public method

public createRequest ( Psr\Http\Message\ServerRequestInterface $psrRequest )
$psrRequest Psr\Http\Message\ServerRequestInterface
コード例 #1
0
 /**
  * @param \Psr\Http\Message\ServerRequestInterface $request
  * @param \Psr\Http\Message\ResponseInterface      $response
  * @param array                                    $args
  *
  * @return \Psr\Http\Message\ResponseInterface
  */
 public function token(Request $request, Response $response, $args)
 {
     $this->logger->info(substr(strrchr(rtrim(__CLASS__, '\\'), '\\'), 1) . ': ' . __FUNCTION__);
     // convert a request from PSR7 to hhtpFoundation
     $httpFoundationFactory = new HttpFoundationFactory();
     $symfonyRequest = $httpFoundationFactory->createRequest($request);
     $bridgeRequest = BridgeRequest::createFromRequest($symfonyRequest);
     $this->oAuth2server->handleTokenRequest($bridgeRequest)->send();
 }
コード例 #2
0
 /**
  * @param \Psr\Http\Message\ServerRequestInterface $request
  * @param \Psr\Http\Message\ResponseInterface      $response
  * @param array                                    $next
  *
  * @return \Psr\Http\Message\ResponseInterface
  */
 public function validateToken($request)
 {
     $this->logger->info(substr(strrchr(rtrim(__CLASS__, '\\'), '\\'), 1) . ': ' . __FUNCTION__);
     // convert a request from PSR7 to hhtpFoundation
     $httpFoundationFactory = new HttpFoundationFactory();
     $symfonyRequest = $httpFoundationFactory->createRequest($request);
     $bridgeRequest = BridgeRequest::createFromRequest($symfonyRequest);
     if (!$this->oAuth2server->verifyResourceRequest($bridgeRequest)) {
         $this->oAuth2server->getResponse()->send();
         die;
     }
     // store the user_id
     $token = $this->oAuth2server->getAccessTokenData($bridgeRequest);
     $this->user = $token['user_id'];
     return TRUE;
 }
コード例 #3
0
 public function testValidRequestShouldBeHandledByTheNextMiddleware()
 {
     $content = '{"content": "This is the content"}';
     $request = Request::create('http://localhost/', 'GET', [], [], [], [], $content);
     $request->headers->set('X-Hub-Signature', sprintf('sha1=%s', hash_hmac('sha1', $content, 'my_secret')));
     $psrFactory = new DiactorosFactory();
     $foundationFactory = new HttpFoundationFactory();
     $psrRequest = $psrFactory->createRequest($request);
     $expectedRequest = $foundationFactory->createRequest($psrRequest);
     $response = new Response('OK');
     $expectedResponse = $foundationFactory->createResponse($psrFactory->createResponse($response));
     $next = $this->prophesize('Symfony\\Component\\HttpKernel\\HttpKernelInterface');
     $next->handle($expectedRequest)->shouldBeCalledTimes(1)->willReturn($response);
     $middleware = new GitHubWebHook($next->reveal(), 'my_secret');
     $response = $middleware->handle($request);
     $this->assertEquals($expectedResponse, $response);
 }
コード例 #4
0
 public function handle(FormInterface $form, ServerRequestInterface $request, ResponseInterface &$response, Authorization $authorization)
 {
     if ('POST' !== $request->getMethod()) {
         return false;
     }
     $httpFoundationFactory = new HttpFoundationFactory();
     $symfony_request = $httpFoundationFactory->createRequest($request);
     $form->submit($symfony_request);
     if (!$form->isValid()) {
         return false;
     }
     $button = $form->get('accept');
     if (!$button instanceof ClickableInterface) {
         throw new InvalidArgumentException('Unable to find the button named "accept".');
     }
     $authorization->setAuthorized($button->isClicked());
     $this->endpoint->authorize($authorization, $response);
 }
コード例 #5
0
 /**
  * @param \Symfony\Component\Form\FormInterface                                                                $form
  * @param \Psr\Http\Message\ServerRequestInterface                                                             $request
  * @param \OAuth2\Endpoint\Authorization\AuthorizationInterface                                                $authorization
  * @param \SpomkyLabs\OAuth2ServerBundle\Plugin\AuthorizationEndpointPlugin\Form\Model\AuthorizationModel      $authorization_model
  *
  * @return bool
  */
 public function handle(FormInterface $form, ServerRequestInterface $request, AuthorizationInterface $authorization, AuthorizationModel $authorization_model)
 {
     if ('POST' !== $request->getMethod()) {
         return false;
     }
     $httpFoundationFactory = new HttpFoundationFactory();
     $symfony_request = $httpFoundationFactory->createRequest($request);
     $form->submit($symfony_request->get($form->getName()));
     if (!$form->isValid()) {
         return false;
     }
     $button = $form->get('accept');
     if (!$button instanceof ClickableInterface) {
         throw new InvalidArgumentException('Unable to find the button named "accept".');
     }
     $authorization->setAuthorized($button->isClicked());
     $refused_scopes = array_diff($authorization->getScopes(), $authorization_model->getScopes());
     foreach ($refused_scopes as $refused_scope) {
         $authorization->removeScope($refused_scope);
     }
     return true;
 }
コード例 #6
0
 public function testCreateRequestWithObjectParsedBody()
 {
     $serverRequest = new ServerRequest('1.1', array(), new Stream(), '/', 'GET', null, array(), array(), array(), array(), new \stdClass(), array());
     $this->assertCount(0, $this->factory->createRequest($serverRequest)->request);
 }
コード例 #7
0
 public function testCreateRequestWithUri()
 {
     $serverRequest = new ServerRequest('1.1', array(), new Stream(), '/', 'GET', new Uri('http://les-tilleuls.coop/about/kevin'), array(), array(), array(), array(), null, array());
     $this->assertEquals('/about/kevin', $this->factory->createRequest($serverRequest)->getPathInfo());
 }