Skip to content

Commit 927ec9a

Browse files
committed
Merge branch 'next' of github.com:devforth/adminforth into inline-create
2 parents 988dfc0 + cf08c59 commit 927ec9a

File tree

5 files changed

+141
-10
lines changed

5 files changed

+141
-10
lines changed
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
---
2+
slug: keycloak-setup-example
3+
title: "Setup AdminForth Authorization via Keycloak"
4+
authors: mpipkun
5+
tags: [keycloak, auth, authorization]
6+
description: "The ultimate guide to setting up AdminForth authorization via Keycloak"
7+
# image: "/ogs/ga-tf-aws.jpg"
8+
---
9+
10+
Keycloak is an open-source identity and access management solution that provides authentication and authorization services. It can be used to secure applications and services by managing user identities, roles, and permissions.
11+
12+
In this guide, we will walk you through the process of setting up AdminForth authorization via Keycloak. Most important we will show you how to set up Keycloak in a Docker container and configure it to work with AdminForth.
13+
14+
## Prerequisites
15+
16+
- Docker installed on your machine
17+
- Basic knowledge of Docker and Docker Compose
18+
19+
## Step 1: Create a Docker Compose File
20+
21+
Create a `docker-compose.yml` file in your project directory. This file will define the Keycloak service and its configuration.
22+
23+
```yaml
24+
services:
25+
pg:
26+
image: postgres:latest
27+
environment:
28+
POSTGRES_USER: demo
29+
POSTGRES_PASSWORD: demo
30+
POSTGRES_DB: demo
31+
ports:
32+
- "5432:5432"
33+
volumes:
34+
- pg-data:/var/lib/postgresql/data
35+
keycloak:
36+
image: quay.io/keycloak/keycloak:latest
37+
command: start-dev --import-realm
38+
environment:
39+
- KEYCLOAK_ADMIN=admin
40+
- KEYCLOAK_ADMIN_PASSWORD=admin
41+
- DB_VENDOR=postgres
42+
- DB_ADDR=pg
43+
- DB_DATABASE=demo
44+
- DB_USER=demo
45+
- DB_PASSWORD=demo
46+
- KEYCLOAK_IMPORT=/opt/keycloak/data/import/keycloak-realm.json
47+
- KEYCLOAK_CLIENT_ID=${KEYCLOAK_CLIENT_ID} # TODO how to generate this values? Are they needed here at all
48+
- KEYCLOAK_CLIENT_SECRET=${KEYCLOAK_CLIENT_SECRET} # TODO how to generate this values? Are they needed here at all
49+
- KEYCLOAK_URL=${KEYCLOAK_URL} # TODO how to generate this values? Are they needed here at all
50+
- KEYCLOAK_REALM=${KEYCLOAK_REALM} # TODO how to generate this values? Are they needed here at all
51+
ports:
52+
- "8080:8080"
53+
depends_on:
54+
- pg
55+
volumes:
56+
- keycloak-data:/opt/keycloak/data
57+
- ./keycloak-realm.json:/opt/keycloak/data/import/keycloak-realm.json
58+
59+
volumes:
60+
keycloak-data:
61+
```
62+
63+
Create `./keycloak-realm.json` file:
64+
65+
```json
66+
{
67+
"id": "AdminforthRealm",
68+
"realm": "AdminforthRealm",
69+
"enabled": true,
70+
"users": [
71+
{
72+
"username": "testuser",
73+
"enabled": true,
74+
"credentials": [
75+
{
76+
"type": "password",
77+
"value": "testpassword"
78+
}
79+
],
80+
"email": "testuser@example.com",
81+
"emailVerified": true
82+
}
83+
],
84+
"clients": [
85+
{
86+
"clientId": "adminforth-client",
87+
"enabled": true,
88+
"publicClient": true,
89+
"redirectUris": ["*"],
90+
"defaultClientScopes": ["openid", "email", "profile"]
91+
}
92+
]
93+
}
94+
```
95+
96+
97+
Run service:
98+
99+
```bash
100+
docker compose -p af-dev-demo up -d --build --remove-orphans --wait
101+
```
102+
103+
104+
# TODO
105+
106+
What to click to generate client ID and secret?

adminforth/documentation/blog/authors.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,3 @@ ivanb:
33
title: Maintainer of AdminForth
44
url: https://github.com/ivictbor
55
image_url: https://avatars.githubusercontent.com/u/1838656?v=4
6-

adminforth/documentation/docs/tutorial/03-Customization/15-afcl.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,23 @@ Default behavior of the Dialog component will allow user to close it by just cli
519519
</div>
520520
</div>
521521

522+
### Dialog open and close
523+
524+
You can open and close dialog by calling `open` and `close` methods.
525+
526+
```ts
527+
528+
const confirmDialog = ref(null);
529+
530+
const openDialog = () => {
531+
confirmDialog.value.open();
532+
}
533+
534+
const closeDialog = () => {
535+
confirmDialog.value.close();
536+
}
537+
```
538+
522539
## Dropzone
523540

524541
```ts

adminforth/documentation/docs/tutorial/05-Plugins/11-oauth.md

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,9 @@ Install Adapter:
221221
npm install @adminforth/keycloak-oauth-adapter --save
222222
```
223223

224-
1. Update your .env file with the following Keycloak configuration:
224+
If you need a basic Keycloak setup which tested with AdminForth, you can follow [this minimal KeyClock setup example](blog/2025-03-25-keycloack/index.md).
225+
226+
1. Update your `.env` file with the following Keycloak configuration:
225227

226228
```bash
227229
KEYCLOAK_CLIENT_ID=adminforth-client
@@ -230,13 +232,7 @@ KEYCLOAK_URL=http://localhost:8080
230232
KEYCLOAK_REALM=AdminforthRealm
231233
```
232234

233-
2. Start Keycloak with Docker:
234-
235-
```bash
236-
docker compose -p af-dev-demo -f inventory.yml up -d --build --remove-orphans --wait
237-
```
238-
239-
3. Create a new user from the back office with the same email as the test user (by default: ```testuser@example.com```)
235+
2. Create a new user from the back office with the same email as the test user (by default: ```testuser@example.com```)
240236

241237
Add the adapter to your plugin configuration:
242238

@@ -332,7 +328,7 @@ plugins: [
332328

333329
Just fork any existing adapter e.g. [Google](https://github.com/devforth/adminforth-google-oauth-adapter) and adjust it to your needs.
334330

335-
This is really easy, you have to change several then 10 lines of code in this [file](https://github.com/devforth/adminforth-google-oauth-adapter/blob/main/index.ts)
331+
This is really easy, you have to change less then 10 lines of code in this [file](https://github.com/devforth/adminforth-google-oauth-adapter/blob/main/index.ts)
336332

337333
Then just publish it to npm and install it in your project.
338334

adminforth/spa/src/afcl/Dialog.vue

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,17 @@ onUnmounted(() => {
9898
modal.value?.destroy();
9999
})
100100
101+
function open() {
102+
modal.value?.show();
103+
}
104+
105+
function close() {
106+
modal.value?.hide();
107+
}
108+
109+
defineExpose({
110+
open: open,
111+
close: close,
112+
})
113+
101114
</script>

0 commit comments

Comments
 (0)