/**
   * Converts a {@link Token} to its equivalent as a {@link JSONObject}.
   *
   * @param token The token.
   * @param scopes The list of scopes.
   * @return An instance of {@link Token} equivalent to the given token.
   * @throws ResourceException
   */
  private JSONObject createJsonToken(Token token, String scopes) throws ResourceException {
    JSONObject body = new JSONObject();

    try {
      body.put(ACCESS_TOKEN, token.getToken());
      if (token instanceof ExpireToken) {
        ExpireToken et = (ExpireToken) token;
        body.put(EXPIRES_IN, et.getExpirePeriod());
        body.put(REFRESH_TOKEN, et.getRefreshToken());
      }
      // TODO add scope
    } catch (JSONException e) {
      throw new ResourceException(Status.SERVER_ERROR_INTERNAL, "Failed to generate JSON", e);
    }

    return body;
  }