'How to export/import a client "WITH ROLES" on Keycloak?

Is it possible to export the client role(s) with the client? If not, is there a workaround (for example modify manually the JSON before reimporting it ?) or another process that can be automated ?



Solution 1:[1]

Yes, you can but it's a little tricky. You have to export entire realm and clean it leaving only this two items:

{
   "roles": {  
    "client": {      
      "<client-name>": [
        {          
          "name": <role-name>,
          "clientRole": true,
           ...
        },
      ]
    }
  },
  "clients": [
    {      
      "clientId": "<client-name>",
      ...
    }
  ]
}

The only thing you cannot do in the same step is importing permissions because import process cannot import permissions based on roles that not exists.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Peter Csala