c'est moi
c'est moi

Reputation: 359

default configuration with embedded keycloak and spring boot app

I'm working with embedded keycloak and spring boot app
I created a realm then I created a client with:
Access Type: confidential
Authorization Enabled: enabled
then I created resources with permission and policy
My problem is :
I want to export this configuration in a config file (java config or json config) so that not every time I have to configure keycloak at the beginning when I restart my keycloak server

How can I do this?

Upvotes: 1

Views: 1116

Answers (1)

dreamcrash
dreamcrash

Reputation: 51543

Update: The /auth path was removed starting with Keycloak 17 Quarkus distribution. So you might need to remove the /auth from the endpoint calls presented on this answer.


You can import/export realms using the Keycloak Admin REST API. To import use the endpoint:

POST <KEYCLOAK_HOST>/auth/admin/realms/<REALM_NAME>/partialImport

and provide the JSON representation of the realm. That representation you can get via Admin Console API by click on Realm > Export > Export. Or using the endpoint:

POST <KEYCLOAK_HOST>/auth/admin/realms/<REALM_NAME>/partial-export?exportClients=true&exportGroupsAndRoles=true

Alternatively, for the export/import you can use:

POST <KEYCLOAK_HOST>/auth/admin/realms

and

GET <KEYCLOAK_HOST>/auth/admin/realms/<REALM_NAME>

respectively.

But then you will need to export/import the clients separately:

GET <KEYCLOAK_HOST>/auth/admin/realms/<REALM_NAME>/clients

and

POST <KEYCLOAK_HOST>/auth/admin/realms/<REALM_NAME>/clients

and provide the JSON representation of the clients.

For a practical example on how to use the Rest API have a look at this answer. That answer is about using the API to create protocols mappers but you can easily adapt it to your use-case.

Upvotes: 2

Related Questions