Authentication¶
Authentication for production¶
Authorization Code flow with PKCE (RFC 7636):
[QGIS Plugin] ──OIDC auth──▶ [Keycloak]
│ │
│ JWT (Bearer token) │ (validates)
▼ ▼
[FastAPI/NiceGUI backend] ◀── JWT validation
│
▼
[NiceGUI frontend, embedded in QGIS WebEngine]
Important detail: the QGIS plugin is the public client in this setup and shouldn't know of the client_secret. The plugin runs on user-controlled machines; any embedded secret can be extracted. PKCE replaces the client secret as proof of possession.
QGIS plugin configuration¶
- Open QGIS authentication settings.
- Create a new authentication configuration.
- Select OAuth2.
- Select PKCE under Permission Flow.
- Set Auth-URL to
http://localhost:8080/realms/xmas/protocol/openid-connect/auth. # For local use, set real value provided by app provider. - Set Token-URL to
http://localhost:8080/realms/xmas/protocol/openid-connect/token. # For local use, set real value provided by app provider. - Set Client-ID to
xmas-plugin. - Set Redirect-URI to
127.0.0.1:17070. - Select this authentication configuration in the XMAS plugin settings.
Dev credentials are username xmas-test-user with password test.
XMAS-App configuration¶
The XMAS-App must be configured to work with Keycloak authentication:
Authentication setup for local development¶
Local development uses a static Bearer token.
QGIS plugin configuration¶
- Open QGIS authentication settings.
- Create a new authentication configuration.
- Select API Header.
- Set the header name to
Authorization. - Set the header value to
Bearer <local-dev-token>. - Select this authentication configuration in the XMAS plugin settings.
XMAS-App configuration¶
The XMAS-App must be configured to accept the same token, for example:
Requests must include:
Authorization: Bearer local-dev-token
The token is mapped to a user ID internally and used as the authenticated user.
This setup is only meant for local development and testing. In production, the static token must be replaced by an active Bearer access token issued through Keycloak.
Rasterdaten (plan documents)¶
Plan document rasters are opened as QgsRasterLayer over GDAL's /vsicurl/ driver. GDAL
fetches these with its own libcurl, so they bypass QgsNetworkAccessManager and with it the
Requester, the broker handshake and the WebEngine request interceptor — none of which GDAL
ever sees.
The plugin therefore hands GDAL the same Authorization: Bearer <token> header out of band,
as a path-specific GDAL_HTTP_HEADERS option scoped to the configured webapp URL
(xmas_plugin/core/network/gdal_auth.py). Because the header is not part of the layer URI,
the token is never written into a saved .qgs project, and the path scoping prevents it from
being sent to any other host.
The header is bound when GDAL opens the dataset. If an access token expires while a raster layer is open, reload the plan to pick up the refreshed token.