try {
final String csrfId = String.valueOf(new SecureRandom().nextLong());
OAuthWebViewData viewData = new OAuthWebViewData(boxClient.getOAuthDataController());
viewData.setOptionalState(String.valueOf(csrfId));
final HtmlPage authPage = webClient.getPage(viewData.buildUrl().toString());
// submit login credentials
final HtmlForm loginForm = authPage.getFormByName("login_form");
final HtmlTextInput login = loginForm.getInputByName("login");
login.setText(configuration.getUserName());
final HtmlPasswordInput password = loginForm.getInputByName("password");
password.setText(configuration.getUserPassword());
final HtmlSubmitInput submitInput = loginForm.getInputByName("login_submit");
// submit consent
final HtmlPage consentPage = submitInput.click();
final HtmlForm consentForm = consentPage.getFormByName("consent_form");
final HtmlButton consentAccept = consentForm.getButtonByName("consent_accept");
// disable redirect to avoid loading redirect URL
webClient.getOptions().setRedirectEnabled(false);