OpenID Connect authentication¶
Ralph LRS also supports OpenID Connect on top of OAuth 2.0 for authentication and authorization.
To enable OpenID Connect authentication mode, we should change the RALPH_RUNSERVER_AUTH_BACKENDS environment variable to oidc and we should define the RALPH_RUNSERVER_AUTH_OIDC_ISSUER_URI environment variable with the identity provider’s Issuer Identifier URI as follows:
RALPH_RUNSERVER_AUTH_BACKENDS=oidc
RALPH_RUNSERVER_AUTH_OIDC_ISSUER_URI=http://{provider_host}:{provider_port}/auth/realms/{realm_name}
This address must be accessible to the LRS on startup as it will perform OpenID Connect Discovery to retrieve public keys and other information about the OpenID Connect environment.
It is also strongly recommended to set the optional RALPH_RUNSERVER_AUTH_OIDC_AUDIENCE environment variable to the origin address of Ralph LRS itself (e.g. “http://localhost:8100”) to enable verification that a given token was issued specifically for that Ralph LRS.
Identity Providers¶
OpenID Connect support is currently developed and tested against Keycloak but may work with other identity providers that implement the specification.
An example with Keycloak¶
The Learning analytics playground repository contains a Docker Compose file and configuration for a demonstration instance of Keycloak with a ralph client.
First, we should stop the Ralph LRS server (if it’s still running):
We can clone the learning-analytics-playground repository:
And then bootstrap the project:
After a couple of minutes, the playground containers should be up and running.
Create another docker compose file, let’s call it docker-compose.oidc.yml, with the following content:
version: "3.9"
services:
lrs:
image: fundocker/ralph:latest
environment:
RALPH_APP_DIR: /app/.ralph
RALPH_RUNSERVER_AUTH_BACKENDS: oidc
RALPH_RUNSERVER_AUTH_OIDC_ISSUER_URI: http://learning-analytics-playground-keycloak-1:8080/auth/realms/fun-mooc
RALPH_RUNSERVER_BACKEND: fs
ports:
- "8100:8100"
command:
- "uvicorn"
- "ralph.api:app"
- "--proxy-headers"
- "--workers"
- "1"
- "--host"
- "0.0.0.0"
- "--port"
- "8100"
volumes:
- .ralph:/app/.ralph
networks:
- ralph
networks:
ralph:
external: true
Again, we need to create the .ralph directory:
Then we can start the lrs service:
Now that both Keycloak and Ralph LRS server are up and running, we should be able to get the access token from Keycloak with the command:
With this access token, we can now make a request to the Ralph LRS server:
Congrats, you’ve managed to authenticate using OpenID Connect! 🎉