Compare commits

..

3 commits

Author SHA1 Message Date
d0cde9f3d8
chore(release): release v0.3.1
All checks were successful
Visitenbuch CI / test (push) Successful in 1m38s
Visitenbuch CI / release (push) Successful in 5m55s
2024-05-13 13:10:52 +02:00
f01fb6f191
test: fix environment files
All checks were successful
Visitenbuch CI / test (push) Successful in 1m24s
Visitenbuch CI / release (push) Has been skipped
2024-05-13 13:01:00 +02:00
8316d4078c
feat: logout user from OIDC provider
Some checks failed
Visitenbuch CI / test (push) Failing after 36s
Visitenbuch CI / release (push) Has been skipped
2024-05-13 04:17:48 +02:00
10 changed files with 54 additions and 10 deletions

View file

@ -1,6 +1,9 @@
# Environment variables to configure the application
# Copy this file to .env and edit the configuration if necessary
DATABASE_URL=postgresql://postgres:1234@localhost:5432/visitenbuch?schema=public DATABASE_URL=postgresql://postgres:1234@localhost:5432/visitenbuch?schema=public
AUTH_SECRET=ptfg+yUj3mQfdPh+5d1ooIkiB7KLO6J2q3jiBhILzE/eabiL # generate with openssl rand -base64 36 AUTH_SECRET=ptfg+yUj3mQfdPh+5d1ooIkiB7KLO6J2q3jiBhILzE/eabiL # generate with openssl rand -base64 36
KEYCLOAK_CLIENT_ID=visitenbuch KEYCLOAK_CLIENT_ID=visitenbuch
KEYCLOAK_CLIENT_SECRET=supersecret KEYCLOAK_CLIENT_SECRET=supersecret
KEYCLOAK_ISSUER=https://example.com/realms/master KEYCLOAK_ISSUER=http://localhost:9090
KEYCLOAK_LOGOUT=http://localhost:9090/session/end

8
.env.test Normal file
View file

@ -0,0 +1,8 @@
# Environment variables for E2E testing
DATABASE_URL=postgresql://postgres:1234@localhost:5432/test?schema=public
AUTH_SECRET=ptfg+yUj3mQfdPh+5d1ooIkiB7KLO6J2q3jiBhILzE/eabiL # generate with openssl rand -base64 36
KEYCLOAK_CLIENT_ID=visitenbuch
KEYCLOAK_CLIENT_SECRET=supersecret
KEYCLOAK_ISSUER=http://localhost:9090
KEYCLOAK_LOGOUT=http://localhost:9090/session/end

View file

@ -23,7 +23,9 @@ jobs:
- name: 👁️ Checkout repository - name: 👁️ Checkout repository
uses: actions/checkout@v4 uses: actions/checkout@v4
- name: 📦 pnpm install - name: 📦 pnpm install
run: pnpm install run: |
pnpm install
cp .env.test .env
- name: 🧐 lint - name: 🧐 lint
run: | run: |
npm run check npm run check

2
.gitignore vendored
View file

@ -4,7 +4,5 @@ node_modules
/.svelte-kit /.svelte-kit
/package /package
.env .env
.env.*
!.env.example
vite.config.js.timestamp-* vite.config.js.timestamp-*
vite.config.ts.timestamp-* vite.config.ts.timestamp-*

View file

@ -3,6 +3,17 @@
All notable changes to this project will be documented in this file. All notable changes to this project will be documented in this file.
## [v0.3.1](https://code.thetadev.de/HSA/Visitenbuch/compare/v0.3.0..v0.3.1) - 2024-05-13
### 🚀 Features
- Logout user from OIDC provider - ([8316d40](https://code.thetadev.de/HSA/Visitenbuch/commit/8316d4078c1ccaf40e9d026c559be2d0c03f92fb))
### 🧪 Testing
- Fix environment files - ([f01fb6f](https://code.thetadev.de/HSA/Visitenbuch/commit/f01fb6f191cf6978252b89656b09144d7fc1cde6))
## [v0.3.0](https://code.thetadev.de/HSA/Visitenbuch/compare/v0.2.1..v0.3.0) - 2024-05-12 ## [v0.3.0](https://code.thetadev.de/HSA/Visitenbuch/compare/v0.2.1..v0.3.0) - 2024-05-12
### 🚀 Features ### 🚀 Features

View file

@ -1,6 +1,6 @@
{ {
"name": "visitenbuch", "name": "visitenbuch",
"version": "0.3.0", "version": "0.3.1",
"private": true, "private": true,
"license": "AGPL-3.0", "license": "AGPL-3.0",
"scripts": { "scripts": {

View file

@ -13,3 +13,15 @@ services:
POSTGRES_PASSWORD: "1234" POSTGRES_PASSWORD: "1234"
volumes: volumes:
- ./postgres:/var/lib/postgresql/data - ./postgres:/var/lib/postgresql/data
oidc:
image: thetadev256/oidc-mock-server
restart: unless-stopped
ports:
- 9090:3000
environment:
CLIENT_ID: visitenbuch
CLIENT_SECRET: supersecret
CLIENT_REDIRECT_URIS: http://localhost:5173/auth/callback/keycloak;http://localhost:4173/auth/callback/keycloak
CLIENT_LOGOUT_REDIRECT_URIS: http://localhost:5173/login?noAuto=1;http://localhost:4173/login?noAuto=1
ISSUER_HOST: localhost:9090

View file

@ -71,7 +71,8 @@ export async function makeAuthjsRequest(
event: RequestEvent, event: RequestEvent,
authjsEndpoint: string, authjsEndpoint: string,
params: Record<string, string>, params: Record<string, string>,
): Promise<never> { noRedirect = false,
): Promise<void> {
const headers = new Headers(event.request.headers); const headers = new Headers(event.request.headers);
headers.set("Content-Type", "application/x-www-form-urlencoded"); headers.set("Content-Type", "application/x-www-form-urlencoded");
@ -85,7 +86,7 @@ export async function makeAuthjsRequest(
for (const c of res?.cookies ?? []) { for (const c of res?.cookies ?? []) {
event.cookies.set(c.name, c.value, { path: "/", ...c.options }); event.cookies.set(c.name, c.value, { path: "/", ...c.options });
} }
return redirect(302, res.redirect ?? ""); if (!noRedirect) return redirect(302, res.redirect ?? "");
} }
export async function auth(event: RequestEvent): Promise<Session | null> { export async function auth(event: RequestEvent): Promise<Session | null> {

View file

@ -1,13 +1,22 @@
import type { Actions } from "./$types"; import type { Actions } from "./$types";
import { redirect } from "@sveltejs/kit";
import { baseUrl } from "$lib/shared/util"; import { baseUrl } from "$lib/shared/util";
import { env } from "$env/dynamic/private";
import { makeAuthjsRequest } from "$lib/server/auth"; import { makeAuthjsRequest } from "$lib/server/auth";
export const actions: Actions = { export const actions: Actions = {
default: async (event) => { default: async (event) => {
const callbackUrl = `${baseUrl(event.url)}/login?noAuto=1`; let callbackUrl = `${baseUrl(event.url)}/login?noAuto=1`;
return makeAuthjsRequest(event, "signout", { callbackUrl }); const cburl = new URL(env.KEYCLOAK_LOGOUT ?? env.KEYCLOAK_ISSUER + "/protocol/openid-connect/logout");
cburl.searchParams.append("post_logout_redirect_uri", callbackUrl);
cburl.searchParams.append("client_id", env.KEYCLOAK_CLIENT_ID);
callbackUrl = cburl.toString();
await makeAuthjsRequest(event, "signout", { }, true);
return redirect(302, callbackUrl);
}, },
}; };

View file

@ -10,7 +10,7 @@ import { makeAuthjsRequest } from "$lib/server/auth";
*/ */
const COOKIE_NAME = "autoLoginTs"; const COOKIE_NAME = "autoLoginTs";
async function doLogin(event: RequestEvent): Promise<never> { async function doLogin(event: RequestEvent): Promise<void> {
const callbackUrl = event.url.searchParams.get("returnURL") ?? baseUrl(event.url); const callbackUrl = event.url.searchParams.get("returnURL") ?? baseUrl(event.url);
return makeAuthjsRequest(event, "signin/keycloak", { callbackUrl }); return makeAuthjsRequest(event, "signin/keycloak", { callbackUrl });