How to call external APIs from a custom field validator?

Does anyone know if it is possible to call external APIs from custom field validators?

Let’s say I wanted to validate a field like username or password (I know password isn’t exposed on user profile but for example) against the HaveIBeenPwnd API?

Is there any good documentation for how to utilize Keycloak’s RestEasy / HttpUtil / etc. to accomplish something like this? I know people suggested on other posts such as this “Can we make an external api call in keycloak files” to use HttpClientProvider but is that the best way in 2023 Keycloak Version 21.0.1?

There’s a nice convenience class for making HTTP requests in Keycloak: SimpleHttp (Keycloak Docs Distribution 21.0.1 API)

You can use it with the session like this:

  SimpleHttp.Response resp =
    SimpleHttp.doPost("https://haveibeenpwned.com/test", session)
    .param("passwd", password)
    .asResponse();

Ok thank you. I remember seeing references to that class but wasn’t sure. I will try using this.