How to install keycloak in local machine
Tags: productivity, webdev, beginners, tutorial
Published: 2020-10-15 16:03:58

---
title: How to install keycloak in local machine
published: true
description: Keycloak Journey
tags: Productivity , webdev, beginners ,tutorial
series: Keycloak Integration
cover_image: https://i.ibb.co/dtkQdhk/Copy-of-Copy-of-Predictor.png
---

Hey there,


![Alt text of image](https://media.giphy.com/media/YOjP742CyBbg0zKCbl/giphy.gif)

<!-- This post assumes there is a front application integrated with keycloak and ready to be connected. :fearful:	

If you looking for how to set up keycloak in front end, I can share it how to do it. Let me know in the comments section. :smile: -->	

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

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


## Setting Up a Keycloak Server
### 1. Download and install keycloak

 * Download the latest version of keycloak from [here] (https://www.keycloak.org/downloads.html) . 
 * 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](https://www.keycloak.org/documentation.html)

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

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](https://i.ibb.co/RhsCK7b/Initial-screen.png)

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](https://i.ibb.co/27TtjpQ/login.png)

### 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](https://i.ibb.co/sCzGV18/add-realm-btn.png)

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


![Alt text of image](https://i.ibb.co/vJ8y7kw/add-realm-screen.png
)

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](https://i.ibb.co/j5K4ssH/clients.png
)

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](https://i.ibb.co/tzvHWtL/add-new-cilent.png)

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](https://i.ibb.co/DKvCw8C/reroute-url.png)

### 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](https://i.ibb.co/Wv9MG2F/roles.png)

Then, we'll add the user role:

![Alt text of image](https://i.ibb.co/K092bcf/add-role.png)

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](https://i.ibb.co/qNcDG75/add-users.png
)

We'll add a user named admin:

![Alt text of image](https://i.ibb.co/3k0sQcC/user-details.png)

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](https://i.ibb.co/1vSJ6pt/reset-password.png)

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

![Alt text of image](https://i.ibb.co/7t0vNFy/add-role-to-admin.png)

<!-- ![Alt text of image](https://i.ibb.co/d2DLyGb/master-init.png)
![Alt text of image](https://i.ibb.co/YQyHGS6/new-realm.png
) -->

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 ! :raised_hands::raised_hands: