Skip to content

Commit 547fad4

Browse files
authored
Merge pull request #97 from itk-dev/feature/local-oidc-mock
feat: run local development against a mock identity provider
2 parents 61b0a25 + 14385a7 commit 547fad4

4 files changed

Lines changed: 74 additions & 12 deletions

File tree

.env.dev

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Committed defaults for the dev environment.
2+
#
3+
# Local development runs against the mock identity provider defined in
4+
# docker-compose.override.yml, because the real one has no redirect URI
5+
# registered for a developer machine. See README.md, "OpenID Connect".
6+
#
7+
# Override any of these in .env.local to point at a different provider.
8+
9+
###> itk-dev/openid-connect-bundle ###
10+
AZURE_AZ_OIDC_METADATA_URL=http://idp.itksites.local.itkdev.dk/.well-known/openid-configuration
11+
# The mock accepts any client id and secret.
12+
AZURE_AZ_OIDC_CLIENT_ID=client-id
13+
AZURE_AZ_OIDC_CLIENT_SECRET=client-secret
14+
AZURE_AZ_OIDC_REDIRECT_URI=https://itksites.local.itkdev.dk/openid-connect/generic
15+
# The application reaches the mock over http inside the docker network. Never
16+
# true anywhere else: since itk-dev/openid-connect 5.1 this governs every
17+
# endpoint the discovery document announces, not only the metadata URL.
18+
AZURE_AZ_OIDC_ALLOW_HTTP=true
19+
###< itk-dev/openid-connect-bundle ###

README.md

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,22 +113,41 @@ Then create a `.env.local` file to set secrets for your local setup.
113113

114114
### OpenID Connect
115115

116-
All users access is controlled by OpenID Connect. For local development you must
117-
add the following to your `.env.local` file:
116+
All user access is controlled by OpenID Connect. Locally the login runs against a
117+
mock identity provider, defined as the `idp` service in `docker-compose.override.yml`
118+
— the real provider has no redirect URI registered for a developer machine.
119+
120+
Start it with the rest of the stack:
121+
122+
```shell
123+
docker compose up --detach
124+
```
125+
126+
Then log in as `admin` or `editor`: the mock shows a form where you type the subject,
127+
and hands back the claims for it. Both identities are defined in the compose file, and
128+
their claims must include `name` and `upn`, which `AzureOIDCAuthenticator` reads.
129+
130+
`.env.dev` carries the settings, so there is nothing to add to `.env.local` for an
131+
ordinary setup. To develop against a real provider instead, override them there:
118132

119133
```dotenv
120134
###> itk-dev/openid-connect-bundle ###
121135
AZURE_AZ_OIDC_METADATA_URL=<value>
122136
AZURE_AZ_OIDC_CLIENT_ID=<value>
123137
AZURE_AZ_OIDC_CLIENT_SECRET=<value>
124138
AZURE_AZ_OIDC_REDIRECT_URI=https://itksites.local.itkdev.dk/openid-connect/generic
139+
AZURE_AZ_OIDC_ALLOW_HTTP=false
125140
###< itk-dev/openid-connect-bundle ###
126141
```
127142

128143
> [!NOTE]
129-
> In the `dev` environment the main firewall security is disabled
130-
> (`security.yaml``when@dev`), so authentication is not required.
131-
> This is because the current AAK OIDC setup doesn't support `itksites.local.itkdev.dk`.
144+
> `AZURE_AZ_OIDC_ALLOW_HTTP=true` in `.env.dev` is what lets the application talk to
145+
> the mock over http inside the docker network. It must never be true anywhere else:
146+
> since `itk-dev/openid-connect` 5.1 it governs every endpoint the discovery document
147+
> announces, not only the metadata URL.
148+
149+
The mock accepts the PKCE challenge the bundle sends but does not verify it, so a
150+
successful login here does not prove PKCE works against Azure.
132151

133152
### Fixtures
134153

config/packages/security.yaml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,6 @@ security:
5858
- { path: ^/admin, roles: ROLE_ADMIN }
5959
# - { path: ^/profile, roles: ROLE_USER }
6060

61-
# Current AAK OIDC setup doesn't support `itksites.local.itkdev.dk`
62-
when@dev:
63-
security:
64-
firewalls:
65-
main:
66-
security: false
67-
6861
when@test:
6962
security:
7063
password_hashers:

docker-compose.override.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,35 @@
11
services:
2+
# A mock identity provider, so the OpenID Connect login can be exercised locally.
3+
# The real one has no redirect URI registered for a developer machine.
4+
#
5+
# https://github.com/geigerzaehler/oidc-provider-mock
6+
#
7+
# The container name is the external hostname on purpose: the browser and the
8+
# application then reach the provider by the same name, so the issuer in the
9+
# discovery document matches the one in the ID token.
10+
#
11+
# Claims must cover what AzureOIDCAuthenticator reads — `name` and `upn`.
12+
idp:
13+
image: ghcr.io/geigerzaehler/oidc-provider-mock:latest
14+
container_name: idp.${COMPOSE_DOMAIN:?}
15+
networks:
16+
- app
17+
- frontend
18+
expose:
19+
- "80"
20+
labels:
21+
- "traefik.enable=true"
22+
- "traefik.docker.network=frontend"
23+
- "traefik.http.routers.${COMPOSE_PROJECT_NAME:?}_idp.rule=Host(`idp.${COMPOSE_DOMAIN:?}`)"
24+
- "traefik.http.services.${COMPOSE_PROJECT_NAME:?}_idp.loadbalancer.server.port=80"
25+
command:
26+
- "--port"
27+
- "80"
28+
- "--user-claims"
29+
- '{"sub": "admin", "name": "Admin Jensen", "upn": "admin@example.org", "email": "admin@example.org"}'
30+
- "--user-claims"
31+
- '{"sub": "editor", "name": "Ed Editor", "upn": "editor@example.org", "email": "editor@example.org"}'
32+
233
rabbit:
334
image: rabbitmq:4-management-alpine
435
networks:

0 commit comments

Comments
 (0)