title: Get access token using refresh token
body: <p>I am currently implementing OAuth2 using <strong>thephpleague/oauth2</strong> library. I have already added the refresh token grant and the access token response already contains the refresh token. However, I don't have any idea how to use that refresh token to get a new access token. </p>
  
  <p>I checked the documentation but I don't see anything about it. The oauth2-client library has methods for it but I'm not going to use that.</p>
  
  <p>My code for the refresh token grant:</p>
  
  <pre><code>$server-&gt;setRefreshTokenStorage(new RefreshTokenStorage);
  
  $refreshTokenGrant = new \League\OAuth2\Server\Grant\RefreshTokenGrant();
  $authCodeGrant = new \League\OAuth2\Server\Grant\AuthCodeGrant();
  
  $server-&gt;addGrantType($authCodeGrant);
  $server-&gt;addGrantType($refreshTokenGrant);
  $response = $server-&gt;issueAccessToken();
  </code></pre>
  
  <p>My question is how can I test that using the refresh token, I can retrieve a new access token? Do I have to implement a new endpoint different from the one that's used by the authorization code grant?</p>
  
  <p>Here is my code for getting the token. Any comments?</p>
  
  <pre><code>public function actionToken(){
  
      $authCodeModel = new \app\models\OAuth_Auth_Codes;
  
      if(!isset($_POST['code'])){
          throw new \yii\web\HttpException(400,"Required parameter \'code\' is missing or invalid.");
      }
  
      $result = $authCodeModel-&gt;find()-&gt;where(['authorization_code' =&gt; trim($_POST['code'])])-&gt;one();
  
      if(!empty($result)){
  
          $user_id = $result-&gt;user_id;
  
          $session2 = new Session();
          $session2-&gt;open();
  
          $server = new AuthorizationServer;
          $server-&gt;setSessionStorage(new SessionStorage);
          $server-&gt;setAccessTokenStorage(new AccessTokenStorage);
          $server-&gt;setClientStorage(new ClientStorage);
          $server-&gt;setScopeStorage(new ScopeStorage);
          $server-&gt;setAuthCodeStorage(new AuthCodeStorage);
          $server-&gt;setRefreshTokenStorage(new RefreshTokenStorage);
  
          $refreshTokenGrant = new \League\OAuth2\Server\Grant\RefreshTokenGrant();
          $authCodeGrant = new \League\OAuth2\Server\Grant\AuthCodeGrant();
  
          $server-&gt;addGrantType($authCodeGrant);
          $server-&gt;addGrantType($refreshTokenGrant);
  
          $response = $server-&gt;issueAccessToken();
  
          $model = new \app\models\OAuth_Access_Tokens();
          $accessTokenModel = $model-&gt;find()-&gt;where(['access_token' =&gt; $response['access_token']])-&gt;one();
          $accessTokenModel-&gt;setAttribute('user_id',''.$user_id);
          $accessTokenModel-&gt;save(FALSE);
  
          return json_encode($response);
      }
      else{
          throw new \yii\web\UnauthorizedHttpException("You have provided an invalid authorization code.");
      }
  }
  </code></pre>