Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
144 commits
Select commit Hold shift + click to select a range
0988c05
initialize springboot project
senaMora Mar 11, 2025
575d50d
Merge pull request #11 from TravelMateAI/dev_planning_kavindu_initiat…
senaMora Mar 11, 2025
99f6a70
initialize a dummy pipeline
senaMora Mar 22, 2025
05fecbd
Merge pull request #12 from TravelMateAI/dev_planning_kavindu_initiat…
senaMora Mar 22, 2025
170f1a6
initial commit for social media service
kokila-13 Apr 7, 2025
383b226
Merge pull request #14 from TravelMateAI/dev_social_media_platform_ko…
KokilaMeddawitage Apr 7, 2025
6e895c7
update
Apr 27, 2025
9888615
some update
May 5, 2025
c3b7884
Merge pull request #15 from TravelMateAI/dev_apigateway
UchihaIthachi May 5, 2025
87f04ce
api service initial implementation
malinduGamage May 13, 2025
c74a132
some fixed
May 13, 2025
dcc866d
Merge pull request #16 from TravelMateAI/dev_apigateway
UchihaIthachi May 13, 2025
cfde3e0
add bookmark logic and some follower logic
May 13, 2025
896d325
add snapshot for keycloack
May 17, 2025
c62909a
ad snapshot for keycloack
May 17, 2025
9200e22
Merge pull request #17 from TravelMateAI/dev_apigateway
UchihaIthachi May 17, 2025
b28e74c
services and routing
malinduGamage May 18, 2025
24dbe62
readme file
malinduGamage May 18, 2025
21e7866
Merge pull request #18 from TravelMateAI/dev_api_service_malindu
malinduGamage May 18, 2025
0304404
auto generated changes of .idea package
senaMora May 30, 2025
4639060
Add keyclock authentication in backend
UchihaIthachi Jun 1, 2025
390b4df
Add keyclock authentication in backend
UchihaIthachi Jun 1, 2025
d873c0d
Add gitignore
UchihaIthachi Jun 1, 2025
ff9696d
Remove ignored directories from tracking
UchihaIthachi Jun 2, 2025
dba1f83
update docker compse
UchihaIthachi Jun 2, 2025
39cb053
Add gitignore
UchihaIthachi Jun 2, 2025
d361b2d
Add gitignore
UchihaIthachi Jun 2, 2025
1767d11
update
UchihaIthachi Jun 3, 2025
9fb72e7
feat: Construct full image URLs in backend
google-labs-jules[bot] Jun 4, 2025
87277d1
feat: Add endpoint for Place Details by ID
google-labs-jules[bot] Jun 4, 2025
3c2382f
fix: Correct utc_offset field name for Place Details API
google-labs-jules[bot] Jun 4, 2025
e122ee3
feat: Add gRPC support for api-service and planning-service
google-labs-jules[bot] Jun 5, 2025
96afe70
Jules was unable to complete the task in time. Please review the work…
google-labs-jules[bot] Jun 5, 2025
1662d28
feat: Implement remaining gRPC methods and add unit tests
google-labs-jules[bot] Jun 5, 2025
81fbca7
refactor: Restructure gRPC services by domain
google-labs-jules[bot] Jun 5, 2025
33d22fc
fix: Correct struct comparisons and field access in maps_server.go
google-labs-jules[bot] Jun 5, 2025
a8cd880
docs: Update gRPC API documentation (api-grpc.md)
google-labs-jules[bot] Jun 5, 2025
98726f5
feat: Add gRPC clients for api-service in planning-service
google-labs-jules[bot] Jun 5, 2025
88fbbab
feat: Add test controller for gRPC clients and update port
google-labs-jules[bot] Jun 5, 2025
ef67129
feat: Add gRPC clients and test controller, refactor packages
google-labs-jules[bot] Jun 5, 2025
4520140
Fix: Explicitly add jackson-datatype-protobuf to resolve build error
google-labs-jules[bot] Jun 5, 2025
3f91e86
Fix: Attempt to resolve jackson-datatype-protobuf with version 2.14.2
google-labs-jules[bot] Jun 5, 2025
a7e1b57
Refactor: Remove jackson-datatype-protobuf, use protobuf-java-util
google-labs-jules[bot] Jun 5, 2025
596bb61
Fix: Restore Jackson for Protobuf serialization
google-labs-jules[bot] Jun 5, 2025
f06c5a8
Fix: Exclude jackson-datatype-protobuf from compileProtoPath
google-labs-jules[bot] Jun 5, 2025
2491cef
Refactor: Use net.devh:grpc-spring-boot-starter for gRPC integration
google-labs-jules[bot] Jun 5, 2025
3d44526
Fix: Align protobuf-java version with protoc compiler
google-labs-jules[bot] Jun 5, 2025
5e29037
Fix: Upgrade net.devh:grpc-spring-boot-starter to 3.0.0.RELEASE
google-labs-jules[bot] Jun 5, 2025
0333699
Fix: Re-add jackson-datatype-protobuf for runtime serialization
google-labs-jules[bot] Jun 5, 2025
6b61cc3
Fix: Re-apply exclusion of jackson-datatype-protobuf from compileProt…
google-labs-jules[bot] Jun 5, 2025
2bbf12e
Alright, I've made a change to address the persistent "Could not find…
google-labs-jules[bot] Jun 5, 2025
a224810
Fix: Downgrade gRPC and Protobuf dependencies to known stable versions
google-labs-jules[bot] Jun 5, 2025
a5cb794
Fix: Definitive Gradle configuration for Protobuf, gRPC, and Jackson
google-labs-jules[bot] Jun 5, 2025
a8dbac6
feat: implement MapService with DTO mapping and update GrpcTestContro…
UchihaIthachi Jun 5, 2025
56df55e
feat: implement MapService with DTO mapping and update GrpcTestContro…
UchihaIthachi Jun 5, 2025
7b56d3a
remove repative files
UchihaIthachi Jun 6, 2025
8b2584f
update
UchihaIthachi Jun 6, 2025
8ff6cbe
fixed typo
UchihaIthachi Jun 6, 2025
db339ef
Refactor gRPC clients to use service layer
google-labs-jules[bot] Jun 6, 2025
0e13ae3
Fix: Consolidate and correct .gitignore files
google-labs-jules[bot] Jun 6, 2025
6f61ba9
Merge pull request #20 from TravelMateAI/fix/consolidate-gitignore
UchihaIthachi Jun 6, 2025
63ea3b7
refactor some add deploy config
UchihaIthachi Jun 6, 2025
4d100fd
fixed spring docker file
UchihaIthachi Jun 9, 2025
433cc3f
fixed golang docker file
UchihaIthachi Jun 9, 2025
0e74846
add complete docker file
UchihaIthachi Jun 9, 2025
02853e7
add temp chages
UchihaIthachi Jun 9, 2025
6ff6a55
updates
UchihaIthachi Jun 9, 2025
81e6e50
update
UchihaIthachi Jun 9, 2025
b53d7fc
update
UchihaIthachi Jun 9, 2025
f2ccd72
finalize the docker & docker compose intergtarion
UchihaIthachi Jun 9, 2025
94d77d3
first phase of oauth2 and refresh token intergration
UchihaIthachi Jun 9, 2025
2324359
add secret data
UchihaIthachi Jun 10, 2025
562e7a3
add deps for oauth2 and refresh token intergration
UchihaIthachi Jun 10, 2025
d517eea
Fix: Correct Keycloak issuer URI and add startup dependency
google-labs-jules[bot] Jun 10, 2025
07d9a34
Refactor: Externalize Keycloak URL and client secret in AuthService
google-labs-jules[bot] Jun 10, 2025
d441fb8
Feat: Add --up flag to deploy.sh as alias for --build --run
google-labs-jules[bot] Jun 10, 2025
29a55ca
Fix: Correct misuse of 'local' keyword in deploy.sh
google-labs-jules[bot] Jun 10, 2025
5e7bcbc
Fix: Tune auth-service health check and clean up docker-compose
google-labs-jules[bot] Jun 10, 2025
c2d42ca
fix deploy issue
UchihaIthachi Jun 11, 2025
d55a20d
fix security issue
UchihaIthachi Jun 12, 2025
9a5e7e5
actions workflow
malinduGamage Jun 13, 2025
7c0a676
actions update
malinduGamage Jun 13, 2025
1333334
actions update2
malinduGamage Jun 13, 2025
d4b70a5
remove installs in docker
malinduGamage Jun 13, 2025
717ba28
pipeline branch adjustment
malinduGamage Jun 13, 2025
658f89d
Update README.md
UchihaIthachi Jun 13, 2025
6070ab6
add .git hub action for oci deploy
UchihaIthachi Jun 13, 2025
94d1185
add setup.sh
UchihaIthachi Jun 13, 2025
674ab31
typo fixed
UchihaIthachi Jun 13, 2025
9762714
fixed typo
UchihaIthachi Jun 13, 2025
e491f92
tmp update
UchihaIthachi Jun 13, 2025
3d693ef
update
UchihaIthachi Jun 13, 2025
742bcbf
docker file chages for arm
UchihaIthachi Jun 13, 2025
dc2d53a
feat(ci): inject secure .env files into OCI deployment from GitHub se…
UchihaIthachi Jun 13, 2025
82e090d
Fix GitHub Actions deployment to Oracle Cloud VM by enabling variable…
UchihaIthachi Jun 13, 2025
015c580
update
UchihaIthachi Jun 13, 2025
1e7ed26
add nginx configertion
UchihaIthachi Jun 13, 2025
8c15ddc
small fix
UchihaIthachi Jun 13, 2025
94107ad
update
UchihaIthachi Jun 13, 2025
ece10c9
update
UchihaIthachi Jun 14, 2025
b86cfc2
update
UchihaIthachi Jun 14, 2025
ecfd5f7
fix
UchihaIthachi Jun 14, 2025
c465bc5
update
UchihaIthachi Jun 14, 2025
c6a82a2
update
UchihaIthachi Jun 14, 2025
c72cf0a
update action file
UchihaIthachi Jun 14, 2025
d922aa5
update
UchihaIthachi Jun 14, 2025
1975b11
update
UchihaIthachi Jun 14, 2025
5932f0b
update
UchihaIthachi Jun 14, 2025
8c36526
update
UchihaIthachi Jun 14, 2025
5aaa8e4
update
UchihaIthachi Jun 14, 2025
b1da8b6
add cors fix
UchihaIthachi Jun 14, 2025
dbbb63e
add cors settings
UchihaIthachi Jun 14, 2025
ee42ca4
disable cors
UchihaIthachi Jun 14, 2025
1d34c00
fixe
UchihaIthachi Jun 14, 2025
7c608bd
updated config files
UchihaIthachi Jun 14, 2025
4390823
update
UchihaIthachi Jun 14, 2025
a4fe771
update
UchihaIthachi Jun 14, 2025
63b3eac
update
UchihaIthachi Jun 15, 2025
119a699
.env chages
UchihaIthachi Jun 15, 2025
5221954
update
UchihaIthachi Jun 15, 2025
56e42ed
update
UchihaIthachi Jun 15, 2025
0e25391
update
UchihaIthachi Jun 15, 2025
77d2388
fixed routing for keyclaock in nginx
UchihaIthachi Jun 15, 2025
9e6b98f
typo fixed
UchihaIthachi Jun 15, 2025
266c901
fixed
UchihaIthachi Jun 15, 2025
3e39075
route fixing in nginx
UchihaIthachi Jun 15, 2025
70a6709
nginx fix
UchihaIthachi Jun 15, 2025
57cf08d
update
UchihaIthachi Jun 15, 2025
0f11585
update keyclaock setup
UchihaIthachi Jun 15, 2025
b523952
update
UchihaIthachi Jun 15, 2025
5405a9c
update compose
UchihaIthachi Jun 15, 2025
c25093d
update properties file
UchihaIthachi Jun 15, 2025
6d5c729
update
UchihaIthachi Jun 15, 2025
e331483
update
UchihaIthachi Jun 15, 2025
8591a45
update
UchihaIthachi Jun 15, 2025
6e229c8
small fixed
UchihaIthachi Jun 15, 2025
9baaf3f
update
UchihaIthachi Jun 15, 2025
836d0aa
update
UchihaIthachi Jun 15, 2025
0f1a324
update
UchihaIthachi Jun 16, 2025
6f79b82
update
UchihaIthachi Jun 16, 2025
3c15b4e
update
UchihaIthachi Jun 16, 2025
a6ce67a
added path finding feature
senaMora Jun 16, 2025
6be012e
update
UchihaIthachi Jun 16, 2025
0396cf0
Merge branch 'dev_oracle' of https://github.com/TravelMateAI/GoTogeth…
UchihaIthachi Jun 16, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
80 changes: 80 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: Deploy to Oracle Cloud VM

on:
push:
branches:
- dev_oracle

jobs:
deploy:
runs-on: ubuntu-latest

env:
OCI_HOST: ${{ secrets.OCI_HOST }}
OCI_USERNAME: ${{ secrets.OCI_USERNAME }}
REPO_NAME: ${{ github.repository }}
API_ENV_CONTENT: ${{ secrets.API_ENV_CONTENT }}
SOCIAL_ENV_CONTENT: ${{ secrets.SOCIAL_ENV_CONTENT }}

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Configure SSH
run: |
mkdir -p ~/.ssh
echo "${{ secrets.OCI_SSH_KEY }}" | tr -d '\r' > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
echo "Host *" > ~/.ssh/config
echo " StrictHostKeyChecking no" >> ~/.ssh/config
echo " UserKnownHostsFile /dev/null" >> ~/.ssh/config

- name: Create temp .env files
run: |
echo "$API_ENV_CONTENT" > api.env
echo "$SOCIAL_ENV_CONTENT" > social.env

- name: Upload .env files to Oracle VM
run: |
scp -i ~/.ssh/id_rsa api.env $OCI_USERNAME@$OCI_HOST:/home/$OCI_USERNAME/app/api-service/.env
scp -i ~/.ssh/id_rsa social.env $OCI_USERNAME@$OCI_HOST:/home/$OCI_USERNAME/app/social-media-service/.env

- name: Deploy to Oracle Cloud Instance
run: |
ssh -i ~/.ssh/id_rsa $OCI_USERNAME@$OCI_HOST <<EOF
set -e

echo "🔄 Updating packages..."
sudo dnf update -y

echo "🐳 Starting Docker..."
sudo systemctl start docker || true
sudo systemctl enable docker || true

echo "🧹 Preparing app directory..."
APP_DIR="/home/$OCI_USERNAME/app"
sudo rm -rf "\$APP_DIR"
mkdir -p "\$APP_DIR"
cd "\$APP_DIR"

echo "📥 Cloning latest code..."
git clone --branch dev_oracle https://github.com/$REPO_NAME.git .

echo "📦 Verifying uploaded .env files..."
ls -l ./api-service/.env || echo "❌ Missing API .env"
ls -l ./social-media-service/.env || echo "❌ Missing Social .env"

echo "📦 Showing contents..."
cat ./api-service/.env || echo "❌ Can't read API .env"
cat ./social-media-service/.env || echo "❌ Can't read Social .env"

echo "🧹 Stopping containers..."
docker-compose -f deploy/docker-compose.yml down || true

echo "🚀 Running deploy.sh..."
chmod +x ./deploy.sh
./deploy.sh --up

echo "🧼 Cleaning Docker..."
docker system prune -f || true
EOF
51 changes: 51 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# General
.idea/
.gradle/
build/
gradle/
bin/
out/
KEYCLOAK_QUICK_SETUP.txt

# IntelliJ IDEA
*.iws
*.iml
*.ipr
/shelf/
/workspace.xml
/httpRequests/
/mavenHomeManager.xml
/dataSources/
/dataSources.local.xml

# STS
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

# NetBeans
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/

# VS Code
.vscode/

# Specific to planning-service
planning-service/HELP.md
planning-service/secret_keys.txt

# Negations (keep these at the end)
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
!**/src/test/**/build/
!**/src/main/**/bin/
!**/src/test/**/bin/
!**/src/main/**/out/
!**/src/test/**/out/
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
# GoTogether-backend
# GoTogether-backend


docker compose exec keycloak /opt/keycloak/bin/kcadm.sh config credentials --server http://localhost:8080 --realm master --user admin --password admin

docker compose exec keycloak /opt/keycloak/bin/kcadm.sh update realms/master -s sslRequired=NONE

http://localhost:8081/admin
46 changes: 46 additions & 0 deletions api-gateway/Dockerfile.kong-oidc
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# FROM kong:3.5

# USER root

# # Install build tools and LuaRocks dependencies
# RUN apt-get update && \
# apt-get install -y --no-install-recommends \
# build-essential \
# git \
# unzip \
# luarocks \
# libssl-dev && \
# rm -rf /var/lib/apt/lists/*

# # Install luaossl with OpenSSL 1.1/3 support
# RUN luarocks install https://luarocks.org/luaossl-20220711-0.src.rock \
# CRYPTO_INCDIR=/usr/include \
# CRYPTO_LIBDIR=/usr/lib/x86_64-linux-gnu \
# OPENSSL_INCDIR=/usr/include \
# OPENSSL_LIBDIR=/usr/lib/x86_64-linux-gnu

# # Install Lua dependencies manually using correct rockspecs (avoids manifest issues)
# RUN luarocks install https://raw.githubusercontent.com/SkyLothar/lua-resty-jwt/master/lua-resty-jwt-0.2.0-1.rockspec && \
# luarocks install https://raw.githubusercontent.com/bungle/lua-resty-session/master/lua-resty-session-3.8-1.rockspec && \
# luarocks install https://raw.githubusercontent.com/zmartzone/lua-resty-openidc/master/lua-resty-openidc-1.7.4-1.rockspec

# # Install kong-oidc plugin
# RUN git clone --branch v1.2.3-2 https://github.com/revomatico/kong-oidc.git && \
# cd kong-oidc && luarocks make && cd .. && rm -rf kong-oidc

# # Install jwt-keycloak plugin
# RUN git clone --branch 20200505-access-token-processing https://github.com/BGaunitz/kong-plugin-jwt-keycloak.git && \
# cd kong-plugin-jwt-keycloak && luarocks make && cd .. && rm -rf kong-plugin-jwt-keycloak

# # Optional: Add your own plugin if needed
# COPY keycloak-introspection /usr/local/share/lua/5.1/kong/plugins/keycloak-introspection

# # Copy your Kong configuration
# COPY config/kong.conf /etc/kong/kong.conf

# USER kong

FROM kong:3.5

# Switch to the kong user
USER kong
7 changes: 7 additions & 0 deletions api-gateway/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
1. Run the scripts in sequence
2. Use user with administrator access (Windows) or root access (Mac / Linux)
3. You don't have to use "root" for Mac / Linux, user with "sudo" access will do
In such case, you need to add "sudo" for each scripts
Example:

$> sudo docker network create --subnet=172.1.1.0/24 kong-net
18 changes: 18 additions & 0 deletions api-gateway/config/kong.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# config/kong.conf
database = postgres
pg_host = kong-database
pg_user = kong
pg_password = mykongpassword
pg_database = kong

plugins = bundled,keycloak-introspection

admin_listen = 0.0.0.0:8001
proxy_listen = 0.0.0.0:8000, 0.0.0.0:8443 ssl

client_id = kong-oidc
client_secret = xxxxxxxx
realm = kong
discovery = http://keycloak:8080/realms/kong/.well-known/openid-configuration
scope = openid
redirect_after_logout_uri = https://localhost/auth/realms/kong/protocol/openid-connect/logout?redirect_uri=https://localhost
89 changes: 89 additions & 0 deletions api-gateway/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
version: "3"

x-kong-env: &kong-env
KONG_DATABASE: postgres
KONG_PG_DATABASE: kong
KONG_PG_HOST: kong-database
KONG_PG_USER: kong
KONG_PG_PASSWORD: kong

volumes:
kong_data: {}
kong_prefix_vol:
driver_opts:
type: tmpfs
device: tmpfs
kong_tmp_vol:
driver_opts:
type: tmpfs
device: tmpfs

networks:
kong-net:
ipam:
config:
- subnet: 172.1.1.0/24

services:
kong-database:
image: postgres:16-alpine
environment:
POSTGRES_DB: kong
POSTGRES_USER: kong
POSTGRES_PASSWORD: kong
volumes:
- kong_data:/var/lib/postgresql/data
networks:
- kong-net
healthcheck:
test: ["CMD", "pg_isready", "-d", "kong", "-U", "kong"]
interval: 30s
timeout: 10s
retries: 3
restart: unless-stopped

kong-migrations:
image: kong:3.5
command: kong migrations bootstrap
environment:
<<: *kong-env
networks:
- kong-net
depends_on:
- kong-database
restart: on-failure

kong:
image: kong:3.5
user: kong
environment:
<<: *kong-env
KONG_ADMIN_ACCESS_LOG: /dev/stdout
KONG_ADMIN_ERROR_LOG: /dev/stderr
KONG_PROXY_LISTEN: 0.0.0.0:8000, 0.0.0.0:8443 ssl
KONG_ADMIN_LISTEN: 0.0.0.0:8001
KONG_ADMIN_GUI_LISTEN: 0.0.0.0:8002
KONG_PROXY_ACCESS_LOG: /dev/stdout
KONG_PROXY_ERROR_LOG: /dev/stderr
KONG_PREFIX: /var/run/kong
KONG_TRACING_INSTRUMENTATIONS: request
ports:
- "8000:8000"
- "8443:8443"
- "8001:8001"
- "8444:8444"
- "8002:8002"
networks:
- kong-net
healthcheck:
test: ["CMD", "kong", "health"]
interval: 10s
timeout: 10s
retries: 10
restart: on-failure
read_only: true
volumes:
- kong_prefix_vol:/var/run/kong
- kong_tmp_vol:/tmp
security_opt:
- no-new-privileges
80 changes: 80 additions & 0 deletions api-gateway/keycloak-introspection/handler.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
-- keycloak-introspection/handler.lua

local http = require("resty.http")
local cjson = require("cjson")

local KeycloakIntrospectionHandler = {
VERSION = "1.0.0",
PRIORITY = 10,
}

function KeycloakIntrospectionHandler:access(config)

-- Get the access token from the request headers
--local access_token = ngx.req.get_headers()["Authorization"]
local access_token= ngx.var.http_authorization

if not access_token then
ngx.log(ngx.ERR, "Access token not found in request headers")
return ngx.exit(ngx.HTTP_UNAUTHORIZED)
end
-- Introspect the access token with Keycloak

local introspection_url = config.keycloak_introspection_url
--local access_token = ngx.var.http_authorization
local httpc = http.new()


local headers = {
["Content-Type"] = "application/x-www-form-urlencoded",
["Authorization"] = "Basic " .. ngx.encode_base64(config.client_id .. ":" .. config.client_secret),
}

local body = "token=" .. access_token

local request_options = {
method = "POST",
body = body,
headers = headers,
}

local res, err = httpc:request_uri(introspection_url, request_options)

ngx.log(ngx.NOTICE, "Entering access function")
ngx.log(ngx.NOTICE, "body ", cjson.encode(request_options))
ngx.log(ngx.NOTICE, "Plugin Configuration :", cjson.encode(config))




if not res then
ngx.log(ngx.ERR, "Failed to introspect token: ", err)
return ngx.exit(ngx.HTTP_INTERNAL_SERVER_ERROR)
end

if res.status ~= 200 then
ngx.log(ngx.ERR, "Token introspection failed with status: ", res.status)
return ngx.exit(ngx.HTTP_UNAUTHORIZED)
end

-- Parse the introspection response
local introspection_result = cjson.decode(res.body)
ngx.log(ngx.NOTICE, "Introspection result: ", res.body)

-- Check if the token is active
if not introspection_result.active then
ngx.log(ngx.ERR, "Access token is not active")
return ngx.exit(ngx.HTTP_UNAUTHORIZED)
end

-- Add introspection result to request headers
ngx.req.set_header("X-User-Id", introspection_result.sub)
ngx.req.set_header("X-Username", introspection_result.username)

ngx.log(ngx.INFO, "Token introspection successful")

-- Close the HTTP connection
httpc:close()
end

return KeycloakIntrospectionHandler
Loading