public function performAccessTokenFlow($directResponse = true, Array $input = array())
  {
    $authServer = $this->getOAuth()->getAuthServer();

    try {

      // Get user input
      if (empty($input)) {
        $input = $this->getRequest()->all();
      }

      // Tell the auth server to issue an access token
      if ($directResponse) {
        return $this->resourceJson($authServer->issueAccessToken($input));
      }

      return $authServer->issueAccessToken($input);

    } catch (ClientException $e) {

      // Throw an exception because there was a problem with the client's request
      $response = array(
        'message'   => $authServer->getExceptionType($e->getCode()),
        'description' => $e->getMessage()
      );

      // make this better in order to return the correct headers via the response object
      $error   = $authServer->getExceptionType($e->getCode());
      $headers = $authServer->getExceptionHttpHeaders($error);

      if ($directResponse) {
        return $this->resourceJson($response, self::$exceptionHttpStatusCodes[$error], $headers);
      }

      $response['status']  = self::$exceptionHttpStatusCodes[$error];
      $response['headers'] = $headers;

      return $response;

    } catch (Exception $e) {

      // Throw an error when a non-library specific exception has been thrown
      $response = array(
        'message'   => 'undefined_error',
        'description' => $e->getMessage()
      );

      if ($directResponse) {
        return $this->resourceJson($response, 500);
      }

      $response['status'] = 500;

      return $response;
    }
  }