2025-01-31 04:34:43 +00:00
|
|
|
# Test app for OIDC, OAuth2 - web app version written with Vue3
|
2025-01-25 02:23:43 +01:00
|
|
|
|
|
|
|
Small web app for experimenting a web app with a Keycloak auth server.
|
|
|
|
|
2025-02-24 04:23:46 +01:00
|
|
|
It is a sibling of the server version [oidc-test](philorg/oidc-fastapi-test),
|
2025-01-31 04:34:43 +00:00
|
|
|
which acts also as a resource server.
|
|
|
|
|
2025-02-24 04:23:46 +01:00
|
|
|
Live demo: <https://philo.ydns.eu/oidc-test-web>:
|
|
|
|
|
2025-01-31 04:34:43 +00:00
|
|
|
- configured with a test realm on a private Keycloak instance
|
|
|
|
- 2 users are defined: foo (foofoo) and bar (barbar).
|
|
|
|
|
2025-02-24 04:23:46 +01:00
|
|
|
**Note**: decoding tokens requires the use of cryto extension,
|
|
|
|
that web browsers allow only with a secured connection (https).
|
|
|
|
|
|
|
|
## Configuration
|
|
|
|
|
|
|
|
The app expects that a `settings.json` file is available on the server
|
|
|
|
at the app's base url.
|
|
|
|
|
|
|
|
For example:
|
|
|
|
|
|
|
|
```json
|
|
|
|
{
|
|
|
|
"keycloakUri": "https://keycloak.your.domain",
|
|
|
|
"realm": "test",
|
|
|
|
"authProvider": "keycloak",
|
|
|
|
"sso": false,
|
|
|
|
"clientId": "oidc-test-web",
|
|
|
|
"tokenSandbox": true,
|
|
|
|
"resourceServerUrl": "https://someserver.your.domain/resourceBaseUrl",
|
|
|
|
"resourceScopes": [
|
|
|
|
"get:time",
|
|
|
|
"get:bs"
|
|
|
|
],
|
|
|
|
"resourceProviders": {
|
|
|
|
"resourceProvider1": {
|
|
|
|
"name": "Third party 1",
|
|
|
|
"baseUrl": "https://otherserver.your.domain/resources/",
|
|
|
|
"verifySSL": true,
|
|
|
|
"resources": {
|
|
|
|
"public": {
|
|
|
|
"name": "A public resource",
|
|
|
|
"url": "resource/public"
|
|
|
|
},
|
|
|
|
"bs": {
|
|
|
|
"name": "A secured resource, eg by scope",
|
|
|
|
"url": "resource/secured1"
|
|
|
|
},
|
|
|
|
"time": {
|
|
|
|
"name": "Another secured resource, eg by role",
|
|
|
|
"url": "resource/secured2"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
## Build
|
2025-01-25 02:23:43 +01:00
|
|
|
|
2025-02-24 04:23:46 +01:00
|
|
|
For generating a `dist` directory ready to be copied to a web server
|
|
|
|
static data tree, it's a straightforward:
|
|
|
|
|
|
|
|
```sh
|
|
|
|
pnpm run build
|
|
|
|
```
|
|
|
|
|
|
|
|
Eventually specify a `base url` (eg. accessible from `https://for.example.com/oidc-test-web`):
|
2025-01-25 02:23:43 +01:00
|
|
|
|
|
|
|
```sh
|
|
|
|
pnpm run build --base oidc-test-web
|
2025-02-24 04:23:46 +01:00
|
|
|
```
|
|
|
|
|
|
|
|
## Deployment
|
|
|
|
|
|
|
|
Examples of deployment are presented below.
|
|
|
|
|
|
|
|
- Using the nginx default container, from the development source tree:
|
|
|
|
|
|
|
|
```sh
|
|
|
|
podman run -it --rm -p 8874:80 -v ./dist:/usr/share/nginx/html/oidc-test-web -v ./settings.json:/usr/share/nginx/html/oidc-test-web/settings.json docker.io/nginx:alpine
|
|
|
|
```
|
|
|
|
|
|
|
|
- The build is packaged in a provided container (see *pakcages*), serving with the `/oidc-test-web` base url:
|
|
|
|
|
|
|
|
```sh
|
|
|
|
podman run -it --rm -p 8874:80 -v ./settings.json:/usr/share/nginx/html/oidc-test-web/settings.json code.philo.ydns.eu/philorg/oidc-vue-test:latest
|
|
|
|
```
|
|
|
|
|
|
|
|
- A *quadlet* *systemd* service, in `~/.config/containers/systemd/oidc-vue-test.container`:
|
|
|
|
|
|
|
|
```systemd
|
|
|
|
[Container]
|
|
|
|
ContainerName=oidc-vue-test
|
|
|
|
Image=code.philo.ydns.eu/philorg/oidc-vue-test:latest
|
|
|
|
Mount=type=bind,source=/path/to/settings.json,destination=/usr/share/nginx/html/oidc-test-web/settings.json
|
|
|
|
PublishPort=8874:80
|
|
|
|
|
|
|
|
[Service]
|
|
|
|
Restart=always
|
|
|
|
RestartSec=5
|
|
|
|
|
|
|
|
[Unit]
|
|
|
|
After=podman-user-wait-network-online.service
|
|
|
|
|
|
|
|
[Install]
|
|
|
|
WantedBy=default.target
|
|
|
|
```
|
|
|
|
|
|
|
|
Run with:
|
|
|
|
|
|
|
|
```sh
|
|
|
|
systemctl --user daemon-reload
|
|
|
|
systemcrl --user start oidc-vue-test
|
2025-01-25 02:23:43 +01:00
|
|
|
```
|
|
|
|
|
|
|
|
## Frontend
|
|
|
|
|
2025-02-24 04:23:46 +01:00
|
|
|
YMMV, easy with *Caddy*:
|
|
|
|
|
2025-01-25 02:23:43 +01:00
|
|
|
```Caddyfile
|
2025-01-31 04:16:36 +00:00
|
|
|
handle /oidc-test-web {
|
2025-01-25 02:23:43 +01:00
|
|
|
reverse-proxy hostname.domainame:8874
|
|
|
|
}
|
|
|
|
redir /oidc-test-web /oidc-test-web/
|
|
|
|
```
|