百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
K

keycloak-security-example

> 前端框架
开源

一个沙箱项目,用于尝试使用 keycloak 并将其与 Spring Boot 和 Angular 应用程序集成(使用 OAuth 2.0 协议)

100 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

一个沙箱项目,用于尝试使用 keycloak 并将其与 Spring Boot 和 Angular 应用程序集成(使用 OAuth 2.0 协议)

keycloak-security-example

This project is all about example implementation of OAuth 2.0 framework, both in a backend and a frontend application. It contains 3 major services:

  • Keycloak (authorization server) - open-source tool for identity and access management,
  • backend (protected resource) - a Java, Spring Boot service that provides a REST API endpoints which requires to provide a valid access token,
  • frontend (client) - an Angular application that make use of backend's protected REST API endpoints.

This project was created for learning purposes, if you would like to know more about OAuth 2.0 in general go check my blog posts listed below.

Prerequisites

To run all necessary applications first you need to install Docker with Docker Compose (for Windows and MacOS it's already bundled with Docker). Instructions can be found on the official website:

  • Ubuntu (Linux),
  • Windows,
  • MacOS.

Instructions for installing Docker Compose on Linux can be found here.

Edit hosts file

Apart from installing Docker you also need to edit hosts file of your OS.

JWT's payload contains a field iss (issuer). It's an URL of an authorization server, in our case Keycloak. In the backend application we need to provide exactly the same URL to the keycloak. But here is the problem that a Docker network and machine's hosts are not the same. From point of view of a backend service a keycloak will have different URL than from point of view of a user!

To mitigate this problem you need to add following lines to the hosts file:

127.0.0.1	keycloak

Location of hosts file on different OS:

  • Linux (Ubuntu)
  • Windows 10
  • Mac

Usage

To run all apps just run following command in a terminal

bash
> docker-compose up -d frontend

It will spin up all necessary parts like Keycloak with its database, frontend and backend service. During first run it might take couple of minutes, becasue Docker images needs to be either downloaded or build. Also first startup of all Docker containers might take awhile, especially a Keycloak container, because it not only run it but also it's applying an initial configuration like a predefined Keycloak realm, users, roles and clients.

To check if everything is working you can list all running containers:

bash
> docker ps

CONTAINER ID    STATUS          PORTS                              NAMES
1840d7564aeb   Up 46 seconds   0.0.0.0:80->80/tcp                 frontend
cba18013881c   Up 47 seconds   0.0.0.0:9000->9000/tcp             backend
01f15608d210   Up 47 seconds   0.0.0.0:8080->8080/tcp, 8443/tcp   keycloak
ac67959019f9   Up 48 seconds   0.0.0.0:5432->5432/tcp             postgres

To check if a Keycloak is good to look at its logs if it contains log Admin console listening on http://127.0.0.1:9990:

…

Once everything is set up you can enter the page http://localhost and it will redirect you to the login page. After providing username and password you can playaround with an app.

In default Keycloak configurarion there is one realm defined - test that has two users:

Username Password Roles
luke password VISITOR
han password ADMIN

To enter the Keyclaok admin page use http://localhost:8080 url where credentials are admin (both for username and password).

Monitoring

Apart from key services in the docker-compose.yaml file there are defined two monitoring services:

  • Prometheus (http://localhost:5000),
  • Grafana (http://localhost:3000).

To run them use on of the following commands:

bash
# this one will run all services defined docker-compose.yaml
> docker-compose up -d

# this one will run only Prometheus and Grafana
> docker-compose up -d grafana

Articles

  • Introduction to OAuth 2.0
  • Create and configure Keycloak OAuth 2.0 authorization server
  • Implementing OAuth 2.0 access token validation with Spring Security
  • Step-by-step guide how integrate Keycloak with Angular application

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Javaangularjavajwtkeycloak

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类前端框架
定价开源

> 相关工具

R
React
用于构建用户界面的 JavaScript 库
V
Vue.js
渐进式 JavaScript 框架
N
Next.js
基于 React 的全栈 Web 框架