DEV Community

Webbies
Webbies

Posted on

Getting Started with Keycloak: Running Your First Instance

As developers, we often face the challenge of implementing secure authentication and authorization in our applications. Keycloak is an open-source Identity and Access Management solution that can significantly simplify this process. In this first part of our three-part series, we'll set up a Keycloak instance using Docker.
Prerequisites

Docker installed on your machine
Basic understanding of authentication concepts
Terminal/Command Prompt access

Setting Up Keycloak with Docker

First, let's create a docker-compose.yml file:

version: '3'
services:
  keycloak:
    image: quay.io/keycloak/keycloak:22.0.1
    environment:
      - KEYCLOAK_ADMIN=admin
      - KEYCLOAK_ADMIN_PASSWORD=admin
    ports:
      - "8080:8080"
    command:
      - start-dev
Enter fullscreen mode Exit fullscreen mode

Start the container:

docker-compose up -d

Your Keycloak instance will be available at http://localhost:8080.
Configuring Keycloak

Navigate to http://localhost:8080/admin and log in with:

Username: admin
Password: admin

Create a new realm:

Click Create Realm
Name it demo-realm
Click Create

Create a client for our applications:

Go to ClientsCreate client
Client ID: demo-app
Client Protocol: openid-connect
Click Next
Enable Client authentication
Click Save

Configure the client:

Valid redirect URIs:

http://localhost:8081/* (for Spring Boot)
http://localhost:4200/* (for Angular)

Web Origins:

http://localhost:8081
http://localhost:4200

Click Save

Create a test user:

Go to UsersAdd user
Username: testuser
Email: testuser@example.com
Click Create
Go to Credentials tab
Set password: password123
Disable Temporary
Click Set Password

Important Configuration Values
Save these values for the next parts:
plaintextCopyRealm: demo-realm
Client ID: demo-app
Client Secret: (find in Clients → demo-app → Credentials tab)
Auth URL: http://localhost:8080/realms/demo-realm
Testing the Setup

Visit http://localhost:8080/realms/demo-realm/.well-known/openid-configuration
You should see a JSON document with endpoint configurations

In the next part, we'll integrate this Keycloak instance with a Spring Boot application.
Stay tuned for Part 2: Integrating Keycloak with Spring Boot!

Image of Datadog

How to Diagram Your Cloud Architecture

Cloud architecture diagrams provide critical visibility into the resources in your environment and how they’re connected. In our latest eBook, AWS Solution Architects Jason Mimick and James Wenzel walk through best practices on how to build effective and professional diagrams.

Download the Free eBook

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more