/**
  * Converts the BrowserKit request to a HttpKernel request.
  *
  * @param DomRequest $request A Request instance
  *
  * @return Request A Request instance
  */
 protected function filterRequest(DomRequest $request)
 {
     $httpRequest = Request::create($request->getUri(), $request->getMethod(), $request->getParameters(), $request->getCookies(), $request->getFiles(), $request->getServer(), $request->getContent());
     /** this happens so we can send oauth2 tokens in the header */
     if (isset($this->server['HTTP_AUTHORIZATION'])) {
         $httpRequest->headers->add(array('HTTP_AUTHORIZATION' => $this->server['HTTP_AUTHORIZATION']));
     }
     $httpRequest->files->replace($this->filterFiles($httpRequest->files->all()));
     return $httpRequest;
 }
Example #2
0
 /**
  * Provide a form in the browser for the user to submit an authorization code.
  * If the request is valid, an access token will be returned
  */
 public function tokenGet(Application $app)
 {
     // render the proper view based on the supplied "grant_type" parameter
     switch ($app['request']->query->get('grant_type')) {
         case 'client_credentials':
             $subRequest = Request::create('/token', 'POST', $app['request']->query->all());
             $response = $app->handle($subRequest, HttpKernelInterface::SUB_REQUEST, false);
             if (!($token = $response->getParameter('access_token'))) {
                 throw new \Exception('failed to get access token from client credentials');
             }
             return $app['twig']->render('token/client_credentials.twig', ['token' => $token, 'client_id' => $app['request']->query->get('client_id'), 'user_id' => $response->getParameter('user_id')]);
         default:
             throw new NotFoundHttpException('Unsupported grant type');
     }
 }