public Session login() {
URI authServerEndpointUri = KeycloakUriBuilder.fromUri(getAuthServerUrl().toExternalForm())
.path(ServiceUrlConstants.TOKEN_SERVICE_DIRECT_GRANT_PATH).build("aerogear");
Session session = Session.newSession(authServerEndpointUri.toString());
// FIXME dont use Session here! Fire up our own RestAssured
Response response = session.given()
.header(Headers.acceptJson())
.formParam("username", username)
.formParam("password", password)
.formParam(OAuth2Constants.CLIENT_ID, "integration-tests")
.post();
if(response.statusCode() == HttpStatus.SC_OK) {
try {
AccessTokenResponse tokenResponse =
JsonSerialization.readValue(response.asString(), AccessTokenResponse.class);
return new Session(getUnifiedPushServerUrl(), tokenResponse);
// FIXME handle the possible io exception!
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException(e);
}