Search in sources :

Example 1 with SelectPage

use of io.jans.as.client.page.SelectPage 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 SelectPage

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

the class SelectAccountHttpTest method selectAccountTest.

@Parameters({ "userId", "userSecret", "userId2", "userSecret2", "redirectUris", "redirectUri", "sectorIdentifierUri" })
@Test
public void selectAccountTest(final String userId, final String userSecret, final String userId2, final String userSecret2, final String redirectUris, final String redirectUri, String sectorIdentifierUri) throws Exception {
    showTitle("authorizationCodeFlow");
    List<ResponseType> responseTypes = Arrays.asList(ResponseType.CODE, ResponseType.ID_TOKEN);
    List<String> scopes = Arrays.asList("openid", "profile", "address", "email", "phone", "user_name");
    RegisterResponse registerResponse = registerClient(redirectUris, responseTypes, scopes, sectorIdentifierUri);
    output("1. Account1 : Request authorization and receive the code and id_token");
    AuthorizationResponse authorizationResponse = requestAuthorization(userId, userSecret, redirectUri, responseTypes, scopes, registerResponse.getClientId(), randomUUID());
    assertNotNull(authorizationResponse, "The authorization response is null");
    assertNotNull(authorizationResponse.getCode(), "The code is null");
    assertIdToken(authorizationResponse.getIdToken());
    String account1SessionId = assertSessionIdCookie();
    output("2. Account2 : Request authorization with prompt=select_account and receive the code and id_token");
    AuthorizationResponse responseFromSelectAccount = selectAccount(userId2, userSecret2, redirectUri, responseTypes, scopes, registerResponse.getClientId(), randomUUID());
    assertNotNull(responseFromSelectAccount, "The authorization response is null");
    assertNotNull(responseFromSelectAccount.getCode(), "The code is null");
    assertIdToken(responseFromSelectAccount.getIdToken());
    String account2SessionId = assertSessionIdCookie();
    assertNotEquals(account1SessionId, account2SessionId);
    output("3. Go again to Select Accounts : we should have 2 accounts");
    AuthorizationRequest authorizationRequest = new AuthorizationRequest(responseTypes, registerResponse.getClientId(), scopes, redirectUri, randomUUID());
    authorizationRequest.setState(randomUUID());
    authorizationRequest.setPrompts(Lists.newArrayList(Prompt.SELECT_ACCOUNT));
    output("4. both Account 1 and Account 2 sessions must be in current_sessions cookie");
    assertEquals(account2SessionId, assertSessionIdCookie());
    List<Object> currentSessions = new JSONArray(driver.manage().getCookieNamed("current_sessions").getValue()).toList();
    assertTrue(currentSessions.contains(account1SessionId));
    assertTrue(currentSessions.contains(account2SessionId));
    output("5. Check that we have 2 buttons for Account 1 and Account 2");
    final SelectPage selectPage = SelectPage.navigate(pageConfig, authorizationEndpoint + "?" + authorizationRequest.getQueryString());
    assertNotNull(selectPage.getAccountButton("Jans Auth Test User"));
    assertNotNull(selectPage.getAccountButton("Jans Auth Test User2"));
    output("6. Switch back to Account 1");
    selectPage.switchAccount(selectPage.getAccountButton("Jans Auth Test User"));
    // check session_id really corresponds to Account 1
    assertEquals(account1SessionId, assertSessionIdCookie());
}
Also used : RegisterResponse(io.jans.as.client.RegisterResponse) AuthorizationRequest(io.jans.as.client.AuthorizationRequest) SelectPage(io.jans.as.client.page.SelectPage) JSONArray(org.json.JSONArray) ResponseType(io.jans.as.model.common.ResponseType) AuthorizationResponse(io.jans.as.client.AuthorizationResponse) Asserter.assertAuthorizationResponse(io.jans.as.client.client.Asserter.assertAuthorizationResponse) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest) BaseTest(io.jans.as.client.BaseTest) AfterTest(org.testng.annotations.AfterTest)

Aggregations

AuthorizationRequest (io.jans.as.client.AuthorizationRequest)2 AuthorizationResponse (io.jans.as.client.AuthorizationResponse)2 Asserter.assertAuthorizationResponse (io.jans.as.client.client.Asserter.assertAuthorizationResponse)2 SelectPage (io.jans.as.client.page.SelectPage)2 BaseTest (io.jans.as.client.BaseTest)1 RegisterResponse (io.jans.as.client.RegisterResponse)1 LoginPage (io.jans.as.client.page.LoginPage)1 ResponseType (io.jans.as.model.common.ResponseType)1 JSONArray (org.json.JSONArray)1 AfterTest (org.testng.annotations.AfterTest)1 BeforeTest (org.testng.annotations.BeforeTest)1 Parameters (org.testng.annotations.Parameters)1 Test (org.testng.annotations.Test)1