/** {@inheritDoc} */
  @Override
  public void setup(OAuth2Settings settings) throws OAuth2SettingsException {
    /* validate supplied settings */
    if (settings == null) {
      throw new OAuth2SettingsException("Missing settings.");
    }
    if (Utils.isNullOrEmpty(settings.getTokenUri())) {
      throw new OAuth2SettingsException("Token server URI missing.");
    } else {
      tokenServer = settings.getTokenUri();
    }
    if (Utils.isNullOrEmpty(settings.getRefreshToken())) {
      throw new OAuth2SettingsException("Refresh token cannot be null or empty.");
    }
    if (Utils.isNullOrEmpty(settings.getClientId())) {
      throw new OAuth2SettingsException("Client ID cannot be null or empty.");
    }
    if (settings.getClientSecret() != null) {
      tokenParams.put("client_secret", settings.getClientSecret());
    }
    if (!Utils.isNullOrEmpty(settings.getScope())) {
      tokenParams.put("scope", settings.getScope());
    }

    /* populate token request params */
    tokenParams.put("client_id", settings.getClientId());
    tokenParams.put("grant_type", "refresh_token");
    tokenParams.put("refresh_token", settings.getRefreshToken());
    for (Entry<String, String> entry : settings.getExtraTokenParams().entrySet()) {
      if (!tokenParams.containsKey(entry.getKey())) {
        tokenParams.put(entry.getKey(), entry.getValue());
      }
    }
  }
  /** {@inheritDoc} */
  @Override
  public void setup(OAuth2Settings settings) throws OAuth2SettingsException {
    /* validate supplied settings */
    if (settings == null) {
      throw new OAuth2SettingsException("Missing settings.");
    }
    if (Utils.isNullOrEmpty(settings.getTokenUri())) {
      throw new OAuth2SettingsException("Token server URI missing.");
    } else {
      tokenServer = settings.getTokenUri();
    }
    if (Utils.isNullOrEmpty(settings.getUsername())) {
      throw new OAuth2SettingsException("Username cannot be null or empty.");
    }
    if (Utils.isNullOrEmpty(settings.getPassword())) {
      throw new OAuth2SettingsException("Password cannot be null or empty.");
    }

    /* populate token request params */
    tokenParams.put("username", settings.getUsername());
    tokenParams.put("password", settings.getPassword());
    tokenParams.put("response_type", "password");
    for (Entry<String, String> entry : settings.getExtraAuthorizeParams().entrySet()) {
      if (!tokenParams.containsKey(entry.getKey())) {
        tokenParams.put(entry.getKey(), entry.getValue());
      }
    }
  }