Skip to content

feat: supporting s2s user context#1592

Draft
davidgamez wants to merge 3 commits intomainfrom
feat/server_to_server_user_context
Draft

feat: supporting s2s user context#1592
davidgamez wants to merge 3 commits intomainfrom
feat/server_to_server_user_context

Conversation

@davidgamez
Copy link
Member

@davidgamez davidgamez commented Feb 4, 2026

Summary:

Closes #1578
Related to MobilityData/mobilitydatabase-web#7
This PR adds support for server-to-server authentication.

Expected behavior:

User context is extracted from the request when the HTTP headers the contains the mdb-user-context JWT signed header.

From our AI friend

This pull request introduces support for a custom user-context JWT for server-to-server authentication, allowing the API to securely identify users based on a shared secret. The changes include decoding and verifying the new JWT, updating request context extraction logic, and ensuring the required secret is available in the deployment environment.

Authentication and user context enhancements:

  • Added a new method decode_user_context_jwt in request_context.py to decode and verify a custom JWT (x-mdb-user-context) using HS256 and a shared secret (S2S_JWT_SECRET). This method safely falls back to existing identity handling if verification fails.
  • Updated _extract_from_headers in request_context.py to extract user information from the custom JWT header, prioritizing verified values and supporting guest users.
  • Introduced the is_guest attribute to the request context to track guest status, and updated related tests to expect this field.

Infrastructure and configuration updates:

  • Modified main.tf to inject the S2S_JWT_SECRET as an environment variable from a secret manager, ensuring secure access to the shared secret for JWT verification.

Dependency management:

  • Added imports for base64, hashlib, hmac, and json in request_context.py to support JWT decoding and verification.

Testing tips:

[internal team]

Please make sure these boxes are checked before submitting your pull request - thanks!

  • Run the unit tests with ./scripts/api-tests.sh to make sure you didn't break anything
  • Add or update any needed documentation to the repo
  • Format the title like "feat: [new feature short description]". Title must follow the Conventional Commit Specification(https://www.conventionalcommits.org/en/v1.0.0/).
  • Linked all relevant issues
  • Include screenshot(s) showing how this pull request works and fixes the issue(s)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SSR: Update Authentication to Firebase Session Management

1 participant