feat(oauth): RFC 8414 authorization server discovery metadata#1132
feat(oauth): RFC 8414 authorization server discovery metadata#1132jjackson wants to merge 1 commit intodimagi:mainfrom
Conversation
Adds /.well-known/oauth-authorization-server serving OAuth 2.0 authorization server metadata per RFC 8414. Modern OAuth clients (including MCP clients) use this to auto-configure rather than hardcoding endpoint URLs. Advertised endpoints: /o/authorize/, /o/token/, /o/introspect/, /o/userinfo/. Code-challenge: S256 only. Scopes sourced from existing oauth2_provider config. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
WalkthroughThis pull request adds OAuth 2.0 Authorization Server metadata discovery functionality. A new view function Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
config/tests/test_oauth_discovery.py (1)
12-14: Add at least one URLconf-level smoke test.
_get()calls the view directly, so these tests can pass even if the.well-knownroute orname="oauth_authorization_server"wiring regresses. Add oneclient.get(reverse("oauth_authorization_server"), secure=True)assertion to cover the actual public endpoint.Example addition
+def test_discovery_route_is_wired(client): + response = client.get(reverse("oauth_authorization_server"), secure=True) + assert response.status_code == 200🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@config/tests/test_oauth_discovery.py` around lines 12 - 14, The tests call the view directly via the helper _get (which uses oauth_authorization_server), so add a URLconf-level smoke test that exercises the real endpoint: in config/tests/test_oauth_discovery.py create a test that uses the Django test client to perform client.get(reverse("oauth_authorization_server"), secure=True) and assert a successful response (e.g., status_code 200 and expected JSON keys), ensuring the .well-known route and the name "oauth_authorization_server" are wired correctly; keep the existing _get helper tests but add this one client-based assertion to cover routing.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@config/views.py`:
- Around line 11-20: The metadata construction uses the incoming request
(request.scheme/request.get_host and absolute()) which makes issuer and endpoint
URLs vary by Host; change it to use the project's canonical public base URL
(e.g. settings.CONNECTID_URL) instead: build the issuer from
settings.CONNECTID_URL and construct authorization/token/introspection/userinfo
endpoints by joining that canonical base with reverse("oauth2_provider:...")
paths (use urllib.parse.urljoin or equivalent) rather than
request.build_absolute_uri; update the absolute() helper to accept a base URL or
remove it and reference settings.CONNECTID_URL where metadata is created so
metadata["issuer"] and the endpoint entries are stable and derived from the
configured CONNECTID_URL, not the request.
---
Nitpick comments:
In `@config/tests/test_oauth_discovery.py`:
- Around line 12-14: The tests call the view directly via the helper _get (which
uses oauth_authorization_server), so add a URLconf-level smoke test that
exercises the real endpoint: in config/tests/test_oauth_discovery.py create a
test that uses the Django test client to perform
client.get(reverse("oauth_authorization_server"), secure=True) and assert a
successful response (e.g., status_code 200 and expected JSON keys), ensuring the
.well-known route and the name "oauth_authorization_server" are wired correctly;
keep the existing _get helper tests but add this one client-based assertion to
cover routing.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 8a0d88ab-9d02-4a59-9baa-efdaa2ce181c
📒 Files selected for processing (4)
config/tests/__init__.pyconfig/tests/test_oauth_discovery.pyconfig/urls.pyconfig/views.py
|
I create this PR because I'm trying to develop a server side MCP for connect-labs to help people more easily edit workflows. Claude thinks this is ideal so I'm not creating a token caching layer to be able to call to use the user's oauth to read/write to the labsrecord apis |
Summary
Adds /.well-known/oauth-authorization-server serving OAuth 2.0 authorization
server metadata per RFC 8414. Enables modern OAuth clients — including a remote
MCP server being built in commcare-connect-labs — to auto-discover endpoints
instead of hardcoding them.
django-oauth-toolkit doesn't ship this endpoint by default, which is why this
needs to be added manually.
What's advertised
Test plan
🤖 Generated with Claude Code