You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
High-Level Desciption : enable site developers to authenticate users against an OIDC IdP (Identity Provider) before granting access to SQL-based pages.
1. Summary of Goals
Allow site developers to configure an OIDC provider (e.g., Google, Microsoft, Keycloak, Okta, Auth0, or other).
Redirect unauthenticated requests to the OIDC IdP: depending on configuration, either redirect all requests, or let developers redirect requests using the authentication component.
Create a special route /_sqlpage/oauth in sqlpage to handle the callback from the Identity Provider to create or verify a user session within the application.
Validate the user’s identity and any pertinent claims (e.g., role, email).
Create a new cookie signed by sqlpage itself containing relevant claims from the original jwt
Create new sqlpage functions to read these claims
Offer configuration options that adapt to different IdPs.
2. Proposed High-Level Architecture
OIDC Configuration
• Add a top-level configuration section (e.g., in the existing configuration file) allowing site administrators to specify OIDC endpoints (authorization, token), client ID, client secret, allowed scopes, etc.
• Store a small subset of user session data (e.g., ID token, user claims) in server-side session storage, protecting against tampering.
OIDC Middleware
• When OIDC is configured and a request should be authenticated, If no valid session is found, redirect the user to the OIDC provider
intercept the request before the execution of the sql,
generate the redirect URL (storing the initial target as state),
return a 307 redirect to the identity provider
Session Management
• Use cookies to track the session info
• Ensure session cleaning or expiration logic when tokens become invalid or time out.
Claim Injection
• Expose user claims (email, groups, roles, etc.) to the request handlers through sqlpage functions, so developers can filter or personalize SQL queries.
3. Step-by-Step Implementation Plan
Step 0: Setup
Run a local Keycloak instance using docker and configure a "sqlpage" client on it.
Do the oidc flow manually with curl to get familiar with it.
Add a github action on CI that runs a preconfigured keycloak.
Step 1: Configuration
Extend the application configuration to include optional OIDC configuration
An OIDC configuration endpoint, such as https://accounts.google.com/.well-known/openid-configuration
An optional OIDC client ID (defaults to sqlpage)
An optional list of sopes to request (defaults to openid, profile, email)
An optional protected area: a path prefix under which all requests will need to be authenticated. Defaults to / when OIDC is configured, to null otherwise.
Step 2: Rust redirection logic
Implement the following logic:
If OIDC is configured AND no valid signed session cookie is present in the request AND
Redirect the user to the identity provider's authorization_endpoint with the client_id from the configuration and a state value that contains the originally requested path
Step 3: Callback Handling
Add a new endpoint that handles the OIDC callback.
Exchange the authorization code for tokens (ID token, access token, refresh token) via the OIDC token endpoint.
Validate the ID token signature and claims.
Set a session cookie referencing this new session. The sessions cookie is a separate JWT signed by sqlpage itself with relevant claims included.
Step 4: Session and Claim Exposure
Add new sqlpage functions to access claims from the sqlpage jwt in the session cookie. sqlpage.user_id(), sqlpage.user_email(), sqlpage.jwt_claim(claim_name). The functions validate the JWT before returning the info. And if the cookie is missing, they trigger the oidc authentication flow with a redirection to the id provider.
Step 5: Documentation and Examples
Provide documentation on the official website for site developers on how to enable OIDC, including:
• Updating the config file with OIDC credentials.
• Setting up the callback URL in their IdP, with examples for popular providers
• Testing the authentication flow.
• Using sqlpage authentication function in SQL queries.
Reference best practices (e.g., always using HTTPS in production).
4. Usage by Site Developers
Configuration – They add their OIDC settings to the config file, including the authorization endpoints, client ID, and secrets.
Callback Setup – They register the callback URL (e.g., “/_sqlpage/oauth”) in their OIDC IdP settings.
SQL Access – Once the user is authenticated, the site developer can use user claims in their queries. For example, they can filter data in an index.sql based on _user_email or _user_roles.
Role-Based Control – If the user needs advanced access control, they can incorporate role checks in the .sql files, rejecting unauthorized roles or restricting queries.
High-Level Desciption : enable site developers to authenticate users against an OIDC IdP (Identity Provider) before granting access to SQL-based pages.
1. Summary of Goals
/_sqlpage/oauth
in sqlpage to handle the callback from the Identity Provider to create or verify a user session within the application.2. Proposed High-Level Architecture
OIDC Configuration
• Add a top-level configuration section (e.g., in the existing configuration file) allowing site administrators to specify OIDC endpoints (authorization, token), client ID, client secret, allowed scopes, etc.
• Store a small subset of user session data (e.g., ID token, user claims) in server-side session storage, protecting against tampering.
OIDC Middleware
• When OIDC is configured and a request should be authenticated, If no valid session is found, redirect the user to the OIDC provider
Session Management
• Use cookies to track the session info
• Ensure session cleaning or expiration logic when tokens become invalid or time out.
Claim Injection
• Expose user claims (email, groups, roles, etc.) to the request handlers through sqlpage functions, so developers can filter or personalize SQL queries.
3. Step-by-Step Implementation Plan
Step 0: Setup
Run a local Keycloak instance using docker and configure a "sqlpage" client on it.
Do the oidc flow manually with curl to get familiar with it.
Add a github action on CI that runs a preconfigured keycloak.
Step 1: Configuration
Extend the application configuration to include optional OIDC configuration
https://accounts.google.com/.well-known/openid-configuration
sqlpage
)/
when OIDC is configured, tonull
otherwise.Step 2: Rust redirection logic
Implement the following logic:
Step 3: Callback Handling
Step 4: Session and Claim Exposure
sqlpage.user_id()
,sqlpage.user_email()
,sqlpage.jwt_claim(claim_name)
. The functions validate the JWT before returning the info. And if the cookie is missing, they trigger the oidc authentication flow with a redirection to the id provider.Step 5: Documentation and Examples
• Updating the config file with OIDC credentials.
• Setting up the callback URL in their IdP, with examples for popular providers
• Testing the authentication flow.
• Using sqlpage authentication function in SQL queries.
4. Usage by Site Developers
index.sql
based on_user_email
or_user_roles
..sql
files, rejecting unauthorized roles or restricting queries.Documentation: https://learn.microsoft.com/en-us/entra/identity-platform/v2-protocols-oidc
This is a follow-up on #82
The text was updated successfully, but these errors were encountered: