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;
}
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());
}
Aggregations