/**
  * @test
  */
 public function it_responds_to_refresh_grant_types()
 {
     $refreshGrant = new \Stormpath\Oauth\RefreshGrantRequest(self::$token->getRefreshTokenString());
     $auth = new \Stormpath\Oauth\RefreshGrantAuthenticator(self::$application);
     $result = $auth->authenticate($refreshGrant);
     $this->assertInstanceOf('Stormpath\\Oauth\\OauthGrantAuthenticationResult', $result);
     $this->assertInstanceOf('Stormpath\\Resource\\AccessToken', $result->getAccessToken());
     $this->assertCount(3, explode('.', $result->getAccessTokenString()));
     $this->assertInstanceOf('Stormpath\\Resource\\RefreshToken', $result->getRefreshToken());
     $this->assertCount(3, explode('.', $result->getRefreshTokenString()));
     $this->assertcontains('/accessTokens/', $result->getAccessTokenHref());
     $this->assertEquals('Bearer', $result->getTokenType());
     $this->assertTrue(is_integer($result->getExpiresIn()));
 }
 private function refreshToken($request)
 {
     $token = $request->cookie(config('stormpath.web.refreshTokenCookie.name'));
     if (!is_string($token)) {
         $token = $token->getValue();
     }
     $cookie = app(CookieJar::class);
     try {
         $refreshGrant = new \Stormpath\Oauth\RefreshGrantRequest($token);
         $auth = new \Stormpath\Oauth\RefreshGrantAuthenticator(app('stormpath.application'));
         $result = $auth->authenticate($refreshGrant);
         $cookie->queue(config('stormpath.web.accessTokenCookie.name'), $result->getAccessTokenString(), $result->getExpiresIn());
         $cookie->queue(config('stormpath.web.refreshTokenCookie.name'), $result->getRefreshTokenString(), $result->getExpiresIn());
         return true;
     } catch (\Stormpath\Resource\ResourceError $re) {
         return false;
     }
 }
 private function refreshCookie($request)
 {
     try {
         $spApplication = app('stormpath.application');
     } catch (\Exception $e) {
         return null;
     }
     $cookie = $request->cookie(config('stormpath.web.refreshTokenCookie.name'));
     if ($cookie instanceof \Symfony\Component\HttpFoundation\Cookie) {
         $cookie = $cookie->getValue();
     }
     try {
         $refreshGrant = new \Stormpath\Oauth\RefreshGrantRequest($cookie);
         $auth = new \Stormpath\Oauth\RefreshGrantAuthenticator($spApplication);
         $result = $auth->authenticate($refreshGrant);
         $this->setNewAccessToken($request, $result);
         return $result->getAccessTokenString();
     } catch (\Stormpath\Resource\ResourceError $re) {
         return null;
     }
 }
 private function doRefreshGrantType($request)
 {
     if (null === $request->input('refresh_token')) {
         return $this->respondWithInvalidRequest('The refresh_token parameter is required.');
     }
     try {
         $refreshGrant = new \Stormpath\Oauth\RefreshGrantRequest($request->input('refresh_token'));
         $auth = new \Stormpath\Oauth\RefreshGrantAuthenticator(app('stormpath.application'));
         $result = $auth->authenticate($refreshGrant);
         return $this->respondWithAccessTokens($result);
     } catch (\Exception $e) {
         return $this->respondWithInvalidLogin($e);
     }
 }