-
Stop the Keycloak container and remove it.
-
In MYSQL run the
DB_setup/MySQL_Keycloak_DB_Setup_Script.sql. -
Start the Keycloak container.
-
To check that it's working open http://localhost:8080.
-
Click on Admin Console http://localhost:8080/auth/admin/. The user and password are
admin. -
Create a
realm_PetStorerealm.Keycloak ref https://www.keycloak.org/docs/latest/server_admin/index.html#_create-realm.
On the left click on the drop down to the right of the
Masterrealm and selectAdd Realm. -
Create realm roles:
admin_role,read_role,write_role-
admin_role -
read_role -
write_roleKeycloak ref: https://www.keycloak.org/docs/latest/server_admin/index.html#realm-roles -
Note: Each client can has their own "client roles", scoped only to the client. Keycloak ref: https://www.keycloak.org/docs/latest/server_admin/index.html#client-roles
-
-
Create users (don't forget to disable
Temporarypassword)Keycloak ref: https://www.keycloak.org/docs/latest/server_admin/index.html#_create-new-user
- login:
admin_user, password:admin_user - login:
read_user, password:read_user - login:
write_user, password:write_user
- login:
-
Add roles to users:
Keycloak ref: https://www.keycloak.org/docs/latest/server_admin/index.html#user-role-mappings
- user:
admin_user, role:admin - user:
read_user, role:read_role - user:
write_user, role:read_role
- user:
-
Create a
PetStore_CLIENTKeycloak ref: https://www.keycloak.org/docs/latest/server_admin/index.html#oidc-clients
- Client ID:
PetStore_CLIENT - Name: ``
- Description: ``
- Enabled:
ON - Always Display in Console:
OFF - Consent Required:
OFF - Login Theme : ``
- Client Protocol:
openid-connect - Access Type:
Confidential - Standard Flow Enabled:
ON - Implicit Flow Enabled:
OFF - Direct Access Grants Enabled:
ON- Important: it should beONfor the custom login (to provide login/password via an application login page) - Service Accounts Enabled:
ON - Authorization Enabled:
ON- Important: to add polices - Root URL : ``
- Valid Redirect URIs:
http://localhost:10010/*. Keycloak will use this value to check redirect URL at least for logout. It can be just a wildcard*. - Base URL : ``
- Admin URL : ``
- Web Origins:
* - Backchannel Logout URL: ``
- Backchannel Logout Session Required:
ON - Backchannel Logout Revoke Offline Sessions:
OFF
- Client ID:
-
Using
Clients -> PetStore_CLIENT -> Rolescreate the following client roles:admin_client_roleread_client_rolewrite_client_roleKeycloak ref: https://www.keycloak.org/docs/latest/server_admin/index.html#client-roles
-
Using
Clients -> PetStore_CLIENT -> Authorization -> Policiesadd role based polices.Keycloak ref: https://www.keycloak.org/docs/latest/authorization_services/index.html#_policy_rbac
Policy Role Admin_Policy admin_role Read_Policy read_role Write_Policy write_role SuperUser_Policy Aggregated Policy* Aggregated Policy* This policy consist of an aggregation of other polices: *
Admin_Policy,Read_Policy,Write_Policy -
Using
Clients -> PetStore_CLIENT -> Mappers ->add scopesKeycloak ref: https://www.keycloak.org/docs/latest/server_admin/index.html#oidc-clients
- Name:
ClientMapper - Mapper Type:
Audience - Included Client Audience:
PetStore_CLIENT - Included Custom Audience: ``
- Add to ID token:
OFF - Add to access token:
ON
- Name:
-
Using
Clients -> PetStore_CLIENT -> Authorization -> "Authorization Scopes"add scopes- petstore:read
- petstore:write
- petstore:admin
-
Using
Clients -> PetStore_CLIENT -> Authorization -> Resourcesadd resourcess. Scopes should be entered in theScopesfield for every resource.Resource Name Scopes res:read petstore:read res:write petstore:write res:admin petstore:admin -
Using
Clients -> PetStore_CLIENT -> Authorization -> Permissionsadd scope-based permissions.Keycloak ref: https://www.keycloak.org/docs/latest/authorization_services/index.html#_permission_create_scope
Set decision strategy for every permission
- Decision Strategy:
Affirmative| Permission | Resource | Scope | Polices | |-----------------|------------|----------------|-------------------| | petstore-read | res:read | petstore:read | Read_Policy | | petstore-write | res:write | petstore:read | Write_Policy | | petstore-admin | res:admin | petstore:admin | SuperUser_Policy |
- Decision Strategy:
-
Using
Clients -> PetStore_CLIENT -> Authorization -> Installationdownloadkeycloak.jsonby selectingKeycloak OIDC JSONdrop down option.Keycloak ref: https://www.keycloak.org/docs/latest/securing_apps/index.html#_nodejs_adapter