Setting up Keycloak Server

Keycloak can be downloaded at :-  https://www.keycloak.org/downloads.html

Once it is downloaded, extract the binary distribution and execute the standalone.sh available in the keycloak-9.0.3/bin to run the keycloak server.

References:- https://www.keycloak.org/docs/latest/server_installation/index.html

 

Adding Realm

We need to add a realm first. This can be done by click on Add realm button on top of the server console.

Screen Shot 2020-04-18 at 3.07.35 PM.png

 

Then add the name for the realm. In my case i have added it as “spring-app-demo-realm“.

1.add_realm.png

Now we have successfully added a realm.

 

Adding new users

Now we need to add new users for the newly added realm. For the demonstration purpose i am filling only the mandatory data. I will be creating two user accounts.

  • username: app-user    /   password: test123
  • username: app-admin    /   password: test123

 

Lets create the “app-user” first.

2.add_user.png

Once the user is added, we need to set the password. This can be done as follows.

3.update_password.png

Repeat the above steps again to create the “admin-user” as well.

 

Create Roles

Now we need to create user roles. we will create following two user roles.

  • ROLE_ADMIN
  • ROLE_USER

 

4. add role.png

 

Screen Shot 2020-05-04 at 3.09.23 PM.png

Now we have successfully created the roles.

 

Assign role(s) for the user

Now this is the time to assign the roles for the user accounts. This can be done as follows.

click on Users. ->  select the user account -> Role Mappings

Assigning the user role for the app-admin user

5. assign role for the user.png

Select the available role(s) -> Add Selected

 

Assigning the user role for the app-user

Screen Shot 2020-05-04 at 3.15.21 PM.png

 

Set up client

Now we need to create new client.

6. add client.png

 

Now we need to do more configurations.

7. configure client.png

 

Now we are done with the setup and configuration process.

 

Testing with Postman

8. testing with POSTman.png

 

REST endpoint should in the following format.

http://localhost:8080/auth/realms/<realm-name>/protocol/openid-connect/token

 

 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s