Search in sources :

Example 1 with LoginPage

use of io.jans.as.client.page.LoginPage in project jans by JanssenProject.

the class SelectAccountHttpTest method selectAccount.

private AuthorizationResponse selectAccount(final String userId, final String userSecret, final String redirectUri, List<ResponseType> responseTypes, List<String> scopes, String clientId, String nonce) {
    String state = UUID.randomUUID().toString();
    AuthorizationRequest authorizationRequest = new AuthorizationRequest(responseTypes, clientId, scopes, redirectUri, nonce);
    authorizationRequest.setState(state);
    authorizationRequest.setPrompts(Lists.newArrayList(Prompt.SELECT_ACCOUNT));
    String authorizationRequestUrl = authorizationEndpoint + "?" + authorizationRequest.getQueryString();
    final SelectPage selectPage = SelectPage.navigate(pageConfig, authorizationRequestUrl);
    final String currentUrl = driver.getCurrentUrl();
    final LoginPage loginPage = selectPage.clickOnLoginAsAnotherUser();
    loginPage.enterUsername(userId);
    loginPage.enterPassword(userSecret);
    loginPage.getLoginButton().click();
    if (ENABLE_REDIRECT_TO_LOGIN_PAGE) {
        loginPage.waitForPageSwitch(currentUrl);
    }
    String authorizationResponseStr = acceptAuthorization(driver, authorizationRequest.getRedirectUri());
    AuthorizationResponse authorizationResponse = buildAuthorizationResponse(authorizationRequest, driver, authorizationResponseStr);
    assertAuthorizationResponse(authorizationResponse, true);
    return authorizationResponse;
}
Also used : AuthorizationRequest(io.jans.as.client.AuthorizationRequest) SelectPage(io.jans.as.client.page.SelectPage) LoginPage(io.jans.as.client.page.LoginPage) AuthorizationResponse(io.jans.as.client.AuthorizationResponse) Asserter.assertAuthorizationResponse(io.jans.as.client.client.Asserter.assertAuthorizationResponse)

Example 2 with LoginPage

use of io.jans.as.client.page.LoginPage in project jans by JanssenProject.

the class DeviceAuthzFlowHttpTest method processDeviceAuthzDenyAccess.

private AuthorizationResponse processDeviceAuthzDenyAccess(String userId, String userSecret, String userCode, WebDriver currentDriver, boolean complete, final PageConfig pageConfig) {
    String deviceAuthzPageUrl = deviceAuthzEndpoint.replace("/restv1/device_authorization", "/device_authorization.htm") + (complete ? "?user_code=" + userCode : "");
    output("Device authz flow: page to navigate to put user_code:" + deviceAuthzPageUrl);
    navigateToAuhorizationUrl(currentDriver, deviceAuthzPageUrl);
    DeviceAuthzPage deviceAuthzPage = new DeviceAuthzPage(pageConfig);
    if (!complete) {
        deviceAuthzPage.fillUserCode(userCode);
    }
    deviceAuthzPage.clickContinueButton();
    Wait<WebDriver> wait = new FluentWait<WebDriver>(currentDriver).withTimeout(Duration.ofSeconds(PageConfig.WAIT_OPERATION_TIMEOUT)).pollingEvery(Duration.ofMillis(500)).ignoring(NoSuchElementException.class);
    if (userSecret != null) {
        final String previousUrl = currentDriver.getCurrentUrl();
        WebElement loginButton = wait.until(d -> currentDriver.findElement(By.id(loginFormLoginButton)));
        LoginPage loginPage = new LoginPage(pageConfig);
        loginPage.enterUsername(userId);
        loginPage.enterPassword(userSecret);
        loginButton.click();
        if (ENABLE_REDIRECT_TO_LOGIN_PAGE) {
            waitForPageSwitch(currentDriver, previousUrl);
        }
    }
    denyAuthorization(currentDriver);
    String deviceAuthzResponseStr = currentDriver.getCurrentUrl();
    stopWebDriver(false, currentDriver);
    output("Device authz redirection response url: " + deviceAuthzResponseStr);
    return new AuthorizationResponse(deviceAuthzResponseStr);
}
Also used : WebDriver(org.openqa.selenium.WebDriver) WebElement(org.openqa.selenium.WebElement) DeviceAuthzPage(io.jans.as.client.page.DeviceAuthzPage) LoginPage(io.jans.as.client.page.LoginPage) AuthorizationResponse(io.jans.as.client.AuthorizationResponse)

Aggregations

AuthorizationResponse (io.jans.as.client.AuthorizationResponse)2 LoginPage (io.jans.as.client.page.LoginPage)2 AuthorizationRequest (io.jans.as.client.AuthorizationRequest)1 Asserter.assertAuthorizationResponse (io.jans.as.client.client.Asserter.assertAuthorizationResponse)1 DeviceAuthzPage (io.jans.as.client.page.DeviceAuthzPage)1 SelectPage (io.jans.as.client.page.SelectPage)1 WebDriver (org.openqa.selenium.WebDriver)1 WebElement (org.openqa.selenium.WebElement)1