How to make a API request in Keycloak login Screen?

Hello, I would like to make a request to an API that returns a certain value for the login screen? Is this possible?

If you’re making it from the client you can use any javascript library within a custom theme.

If you’re needing to make a server-side request you can implement a custom form provider SPI and extends the FreeMarkerLoginFormsProvider to add your “certain value” to the templating context and access it from a custom theme.

e.g.

MyCustomFormProvider extends FreeMarkerLoginFormsProvider {

    @Override
    protected void createCommonAttributes(Theme theme, Locale defaultLocale, Properties messagesBundle,
                                          UriBuilder baseUriBuilder, LoginFormsPages page) {
        super.createCommonAttributes(theme, defaultLocale, messagesBundle, baseUriBuilder, page);
        attributes.put("myValue", ...);
    }
}

If you go with a server-side approach, keep in mind that the form provider is called for ALL form renders; you’ll need to do some checks to only run your code for your specific theme if that’s not desired.