DEV Community

Cover image for How to install keycloak in local machine
Sandeep Balachandran
Sandeep Balachandran

Posted on • Edited on

How to install keycloak in local machine

Hey there,

Alt text of image

Let us talk about Keycloak for a moment.
What is a keycloak you ask?
Let me explain.

Keycloak is an open source software product to allow single sign-on with Identity and Access Management aimed at modern applications and services - Google

Basically you can add authentication to applications and secure services with minimum fuss . Less headache in one word. Nop. Two words.

Let's see how we can set up this service in our environment. I am focusing windows platform for now. The examples are done in windows environment.

What we are going to cover here

✅ Download and install keycloak
✅ Creating a Realm
✅ Creating a client
✅ Creating a Role and a User
✅ Login With the credential

Setting Up a Keycloak Server

1. Download and install keycloak

  • Download the latest version of keycloak from here .
  • Take the zip file
  • At the time of writing this i am using keycloak 11.0.2

If java is not installed,

  • Install Java sdk
  • Add the path to environmental variables

Official documentation is right here



unzip keycloak-11.0.2.zip 
cd keycloak-11.0.2/bin
standalone.bat -Djboss.socket.binding.port-offset=100


Enter fullscreen mode Exit fullscreen mode

After running ./standalone.sh, Keycloak will be starting its services. Once we see a line containing Keycloak 11.0.2 (WildFly Core 12.0.3.Final) started
Now let's open a browser and visit http://localhost:8180. We'll be redirected to http://localhost:8180/auth to create an administrative login as you can see below.

Alt text of image

Let's create an initial admin user named 'admin' with the password 'password'.(education purpose only).
Upon clicking Create, we'll see a message User Created.

We can now proceed to the Administrative Console. On the login page, we'll enter the initial admin user credentials

Alt text of image

2. Creating a Realm

A successful login will take us to the console and open up the default Master realm for us.

Here we'll focus on creating a custom realm.

Let's navigate to the upper left upper corner to discover the Add realm button:

Alt text of image

On the next screen, let's add a new realm called AngularKeycloak:

Alt text of image

After clicking the Create button, a new realm will be created and we'll be redirected to it. All the operations in the next sections will be performed in this new AngularKeycloakrealm.

3. Creating a client

Now we'll navigate to the Clients page. As we can see in the image below, Keycloak comes with Clients that are already built-in

Alt text of image

But we need to add a new client to our application, so we'll click Create. We'll call the new Client angular-app:

Alt text of image

In the next screen we'll be leaving all the defaults except the Valid Redirect URIs field. This field should contain the application URL(s) that will use this client for authentication:

Alt text of image

4. Creating a Role and a User

Keycloak uses Role-Based Access. Therefore, each user must have a role.

To do that, we need to navigate to the Roles page:

Alt text of image

Then, we'll add the user role:

Alt text of image

Now we've got a role that can be assigned to users, but there are no users yet. So let's go the Users page and add one:

Alt text of image

We'll add a user named admin:

Alt text of image

We can now go to the Credentials tab. Set a password. Remember you need username and password you set right now to login with this user for your application:

Alt text of image

Finally, we'll navigate to the Role Mappings tab. We'll be assigning the user role to our user1:

Alt text of image

You have succesfully installed Keycloak at this point. Now you can connect your application to keycloak for identity and access management.

We will see how to add custom themes for keycloak in the next post.

Thats it for now. Hasta Pronto ! 🙌🙌

Top comments (0)