private void passwordFlowDemo() {
withApiClient(client(), singletonList(SphereProjectScope.VIEW_PRODUCTS), apiClient -> {
withCustomer(client(), (Customer customer) -> {
final SphereAuthConfig authConfig = toSphereAuthConfig(getSphereClientConfig(),apiClient);
final String email = customer.getEmail();
final String pw = CustomerFixtures.PASSWORD;
final Tokens tokens = blockingWait(TokensFacade.
fetchCustomerPasswordFlowTokens(authConfig, email, pw), 2, SECONDS);
final String accessToken = tokens.getAccessToken();
assertThat(accessToken).isNotEmpty();
try (final SphereClient client = SphereClientFactory.of()
.createClient(getSphereClientConfig(), SphereAccessTokenSupplier.ofConstantToken(accessToken))) {
final PagedQueryResult<ProductProjection> customerPagedQueryResult =
blockingWait(client.execute(ProductProjectionQuery.ofCurrent().withLimit(1)), 2, SECONDS);
assertThat(customerPagedQueryResult).isNotNull();
}
});
});
}
}