I am writing integration tests in which I use testcontainers with keycloak 24.0.5. I want to enable totp for the admin realm. It's easy to set this setting in the GUI but I need to set it automatically. Is there a way to do this using the admin rest api? I've been trying to do this using an update endpoint for auth flows but unfortunately, this results in a http 202 status code. I am very thankful for any hint.
It's easy to set this setting in the GUI but I need to set it automatically.
You can do all the things using REST which are possible though GUI. Keycloak documentation does not provide all the endpoints. You can refer to the REST calls made by GUI by analyzing network calls from debugger.
How to use REST APIs?
Use temporary Keycloak admin credentials (which you must have created while installing keycloak) to generate access token.
MASTER_TOKEN=$(curl --silent --location --request POST "http://localhost:8080/realms/master/protocol/openid-connect/token" \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'client_id=admin-cli' \
--data-urlencode 'grant_type=password' \
--data-urlencode 'username=admin' \
--data-urlencode 'password=admin' | jq -r '.access_token')
Using this token, you can perform all the operations that you are performing from GUI.