Import/Export Client Scopes in a realm

Hello,

Is there a way to import client Scopes in a realm ?

Thanks for the help.

Can you provide more detail? The realm import functionality will import Client Scopes if they are present in the realm json file you are importing.

image

I have added scope the way it is mentioned in the image above. If I am doing it wrong, please let know.

Thank you for your reply.

That looks right. However, are you doing it manually? Why not just create a realm in the admin UI, create and map the Client Scopes, and then export the realm?

https://www.keycloak.org/docs-api/13.0/rest-api/index.html#_clientscoperepresentation

1 Like

Actually I have to use import functionality because I have created different realms but client scopes in all of them are same. So instead of creating it every time I thought to import it.

However, can you elaborate on your point: Why not just create a realm in the admin UI, create and map the Client Scopes, and then export the realm?

There is a section of the Admin UI called “Export”, where you can export the realm. Check “Export clients” when you are exporting, so that it will include Clients and Client Scopes:


Once you have done that, you can use that file to import the realm elsewhere.

1 Like

I totally got the export feature.

Now, for example:
I have 2 realms: one is “demo” and another is “demo1”. I created a scope “sample-scope” in demo realm using the section of the Admin UI called “Client Scopes”. And now I want the same client scope in realm “demo1”. So I exported realm json files of both the realms and then I copied the “sample-scope” curl data from “demo” realm json file and pasted in “demo1” realm json file. Now I imported the demo1 realm json file but the scope was not imported.

Is it the proper way ?

That should work. Do you see any errors in the Keycloak logs?

No, there are no errors. File gets imported successfully.

While importing I only get three options which are mentioned in the image attached below:

image

as divya mentioned above, I have same issue, that the configurations of client-scopes exported in json could not be imported in realm.