/** * This function will take the client_id, client_secret, refresh_token, grant_type=refresh_token * and then return the token. * @param Request $request * @return new access token for user */ public function newAccessToken(Request $request) { //added it to post as not injecting direclty in Request object $_POST['client_secret'] = env('APP_KEY'); $bridgedRequest = \OAuth2\HttpFoundationBridge\Request::createFromGlobals($request->instance()); $bridgedRequest->headers->add(['client_secret' => env('APP_KEY')]); $bridgedResponse = new \OAuth2\HttpFoundationBridge\Response(); $bridgedResponse = \App::make('oauth2')->grantAccessToken($bridgedRequest, $bridgedResponse); if ($bridgedResponse) { return response(['data' => ['access_token' => $bridgedResponse['access_token'], 'refresh_token' => $bridgedResponse['refresh_token'], 'expires_in' => $bridgedResponse['expires_in']], 'message' => 'New access token', 'flag' => true], 201); } return response(['message' => 'Invalid refresh token', 'flag' => false], 500); }
<?php use OAuth2\HttpFoundationBridge\Request; $app = (require_once __DIR__ . '/../bootstrap.php'); /* * Repeated in the client * * A big hack. In Behat, I was seeing that Guzzle was making requests to * localhost:9002 (the host I was using locally). But when it hit the application, * the HTTP_HOST header was "localhost" instead of "localhost:9002", which * caused the port to be wrong on all generated links. This hacks around * whatever bug (on my end or another) that caused that. */ $host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : null; $port = isset($_SERVER['SERVER_PORT']) ? $_SERVER['SERVER_PORT'] : null; if (!in_array($port, array('80', '443')) && false === ($pos = strrpos($host, ':'))) { $_SERVER['HTTP_HOST'] .= ':' . $port; } $request = Request::createFromGlobals(); $app->run($request);