Skip to content

Commit ce13e13

Browse files
authored
Merge pull request #19 from Halbes-Byte/feature/auth
feature/auth: Implement authorization
2 parents 8456d1a + 8f880e8 commit ce13e13

File tree

14 files changed

+2803
-12
lines changed

14 files changed

+2803
-12
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ target/
55
start_vpn.sh
66
server/generated-sources/
77
data/
8+
.env

docker-compose.yml

Lines changed: 53 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,53 @@
1-
services:
2-
backend:
3-
build:
4-
context: .
5-
dockerfile: Dockerfile
6-
image: panderu/study-buddies-backend:latest
7-
container_name: backend
8-
ports:
9-
- "8080:8080"
1+
services:
2+
keycloak_web1:
3+
image: keycloak/keycloak:latest
4+
container_name: kc-web1
5+
environment:
6+
KC_DB: postgres
7+
KC_DB_URL: jdbc:postgresql://keycloakdb1:5432/keycloak
8+
KC_DB_USERNAME: ${KC_DB_USERNAME}
9+
KC_DB_PASSWORD: ${KC_DB_PASSWORD}
10+
11+
KEYCLOAK_ADMIN: ${KC_DB_USERNAME}
12+
KEYCLOAK_ADMIN_PASSWORD: pass
13+
14+
15+
KC_HOSTNAME: localhost
16+
KC_HOSTNAME_PORT: 8080
17+
KC_HOSTNAME_STRICT: 'false'
18+
KC_HOSTNAME_STRICT_HTTPS: 'false'
19+
KC_LOG_LEVEL: debug
20+
21+
KC_METRICS_ENABLED: 'true'
22+
KC_HEALTH_ENABLED: 'true'
23+
KC_PROXY: edge
24+
KC_PROXY_HEADERS: forwarded
25+
command: start-dev
26+
depends_on:
27+
- keycloakdb1
28+
ports:
29+
- '7070:8080'
30+
######################################################
31+
keycloakdb1:
32+
image: postgres:15
33+
volumes:
34+
- postgres_data:/var/lib/postgresql/data
35+
environment:
36+
POSTGRES_DB: keycloak
37+
POSTGRES_USER: ${KC_DB_USERNAME}
38+
POSTGRES_PASSWORD: ${KC_DB_PASSWORD}
39+
ports:
40+
- '5432:5432'
41+
#spring:
42+
# build:
43+
# context: .
44+
# dockerfile: Dockerfile
45+
# # image: panderu/study-buddies-backend:latest
46+
# container_name: spring-backend
47+
# ports:
48+
# - "1516:8080"
49+
# depends_on:
50+
# - keycloak_web
51+
######################################################
52+
volumes:
53+
postgres_data:

realms/README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# How to setup a new Keycloak instance
2+
*summary of [this Tutorial](https://medium.com/@nishada/keycloak-spring-boot-rbac-e8732a91909a)*
3+
4+
1. Create Realm
5+
2. Ressource file: `sb-backend.json` (may take a minute or two)
6+
3. Users → Add User → **fill all fields** (Username, Email, First name, Last name) otherwise there will be an error → Create
7+
4. Users → Click on User → Credentials → Set password → **NOT TEMPORARY**
8+
5. Users → Click on User → Role mapping → Add Admin / Student role
9+
10+
# How to request a JWT Token using Postman
11+
1. Create Post Request to `http://localhost:7070/realms/study-buddies/protocol/openid-connect/token`
12+
2. Set `Body` → `x-www-form-urlencoded`:
13+
14+
|Key|Value|
15+
|:-:|:-:|
16+
|client_id|sb-backend|
17+
|grant_type|password|
18+
|username|User created above|
19+
|password|Password of user created above|
20+
21+
3. *Optional:* View content of `access_token` [here](https://jwt.io/).
22+
23+
# How to use a restricted endpoint using Postman
24+
1. Create Request
25+
2. Authorization → Auth Type: Bearer Token → paste full content of `access_token` from JWT request above into `Token` field.
26+

0 commit comments

Comments
 (0)