A minimal example of using OIDC with Symfony.
Configure Keycloak:
- Start the compose project:
docker compose up -dThis boots up a local Keycloak instance; - Go to http://localhost:8080/admin/master/console and login using
admin:admin; - Navigate to Realm settings and under "Tokens", set the "Default Signature Algorithm" to "ES256";
- Navigate to Clients and create a new client. Enable the "Client authentication" switch;
- In the client under "Credentials", copy the "Client secret";
Configure Symfony:
- Define the Client ID and Secret from Keycloak in the
OIDC_CLIENT_IDandOIDC_CLIENT_SECRETenv vars; - Visit http://localhost:8080/realms/master/protocol/openid-connect/certs
(replace
masterwith the Realm ID if you created a new Realm in Keycloak); - Select the item with
alg: "ES256"and copy the object as JSON ({"kid":"...","kty":"EC","alg":"ES256",...}). Store this as text in theOIDC_JWKenv var.
Start the Symfony app:
- Run
symfony serve -dand navigate to https://localhost:8000 and follow the instructions on the page.