Skip to content

Commit a6a25d3

Browse files
Muhammad Faraz  MaqsoodMuhammad Faraz  Maqsood
authored andcommitted
docs: add ADR for standardizing authentication patterns
1 parent 2e2ebb9 commit a6a25d3

1 file changed

Lines changed: 151 additions & 0 deletions

File tree

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
Standardize Authentication Patterns and Security Schemes
2+
========================================================
3+
4+
:Status: Proposed
5+
:Date: 2026-04-07
6+
:Deciders: Open edX Platform / API Working Group
7+
:Technical Story: Open edX REST API Standards - Consistent authentication patterns and security scheme usage
8+
9+
Context
10+
=======
11+
12+
Open edX APIs have inconsistent authentication patterns and security scheme implementations:
13+
14+
* Some APIs use OAuth2, others use JWT, some use session authentication
15+
* Multiple authentication mechanisms are enabled globally but not consistently applied
16+
* Security scheme declarations don't match actual authentication behavior
17+
* External integrators cannot reliably predict which authentication method to use
18+
* Internal APIs mix authentication mechanisms without clear patterns
19+
20+
This inconsistency creates confusion for:
21+
- External developers determining which auth method to implement
22+
- Internal teams maintaining consistent authentication patterns
23+
- Security reviews and compliance assessments
24+
- Automated tools expecting predictable authentication
25+
26+
Decision
27+
========
28+
29+
1. **OAuth2 via Django OAuth Toolkit (DOT) MUST be the standard authentication
30+
mechanism for external API access**
31+
2. **JWT authentication MUST be used only for internal service-to-service communication**
32+
3. **Session authentication MUST be used only for browser-based UI interactions**
33+
4. **All new APIs MUST follow these authentication patterns based on use case**
34+
5. **Existing APIs MUST be audited and updated to follow consistent patterns**
35+
36+
Implementation requirements:
37+
38+
* External APIs (public, partner integrations): OAuth2 only
39+
* Internal APIs (service-to-service): JWT only
40+
* Browser-based APIs (UI interactions): Session only
41+
* DRF authentication classes must match the intended use case
42+
* No mixing of authentication mechanisms in single endpoints
43+
44+
Consequences
45+
============
46+
47+
* Pros
48+
49+
* Clear, predictable authentication patterns for different API use cases
50+
* Improved security through proper separation of auth mechanisms
51+
* Easier integration for external developers (OAuth2 standard)
52+
* Simplified internal service communication (JWT)
53+
* Better browser experience (session-based auth)
54+
55+
* Cons / Costs
56+
57+
* Existing APIs need audit and potential refactoring to match patterns
58+
* Teams need to understand and implement proper authentication choices
59+
* Some APIs may need to be split or redesigned for single auth mechanism
60+
* Migration effort for services currently using mixed authentication
61+
62+
Relevance in edx-platform
63+
=========================
64+
65+
* **OAuth2/DOT**: LMS uses Django OAuth Toolkit at ``/oauth2/``
66+
(``lms/urls.py``, ``openedx/core/djangoapps/oauth_dispatch``). Settings include
67+
``OAUTH2_PROVIDER_APPLICATION_MODEL``, ``OAUTH2_VALIDATOR_CLASS`` (e.g.
68+
``EdxOAuth2Validator``).
69+
* **Current API auth**: ``openedx/core/lib/api/view_utils.view_auth_classes``
70+
configures both **JWT** and **OAuth2** (Bearer) and session:
71+
72+
.. code-block:: python
73+
74+
# openedx/core/lib/api/view_utils.py (current)
75+
func_or_class.authentication_classes = (
76+
JwtAuthentication,
77+
BearerAuthenticationAllowInactiveUser, # OAuth2 Bearer via DOT
78+
SessionAuthenticationAllowInactiveUser
79+
)
80+
81+
* **Bearer auth**: ``openedx/core/lib/api/authentication.py`` implements
82+
``BearerAuthentication`` / ``BearerAuthenticationAllowInactiveUser`` using
83+
``oauth2_provider`` (DOT) for access token validation.
84+
85+
Code examples (authentication patterns by use case)
86+
===================================================
87+
88+
* **External API (OAuth2 only):**
89+
90+
.. code-block:: python
91+
92+
from rest_framework import viewsets
93+
from openedx.core.lib.api.authentication import BearerAuthenticationAllowInactiveUser
94+
from rest_framework.permissions import IsAuthenticated
95+
96+
class ExternalCourseViewSet(viewsets.ViewSet):
97+
"""External API for course data - OAuth2 authentication only."""
98+
authentication_classes = [BearerAuthenticationAllowInactiveUser]
99+
permission_classes = [IsAuthenticated]
100+
101+
* **Internal Service API (JWT only):**
102+
103+
.. code-block:: python
104+
105+
from rest_framework import viewsets
106+
from openedx.core.lib.api.authentication import JwtAuthentication
107+
from rest_framework.permissions import IsAuthenticated
108+
109+
class InternalServiceViewSet(viewsets.ViewSet):
110+
"""Internal service-to-service API - JWT authentication only."""
111+
authentication_classes = [JwtAuthentication]
112+
permission_classes = [IsAuthenticated]
113+
114+
* **Browser-based API (Session only):**
115+
116+
.. code-block:: python
117+
118+
from rest_framework import viewsets
119+
from openedx.core.lib.api.authentication import SessionAuthenticationAllowInactiveUser
120+
from rest_framework.permissions import IsAuthenticated
121+
122+
class BrowserUIViewSet(viewsets.ViewSet):
123+
"""Browser UI API - Session authentication only."""
124+
authentication_classes = [SessionAuthenticationAllowInactiveUser]
125+
permission_classes = [IsAuthenticated]
126+
127+
Implementation Notes
128+
====================
129+
130+
* Audit existing APIs to identify authentication pattern violations
131+
* Create guidelines for determining appropriate authentication mechanism
132+
* Update global authentication configurations to enforce patterns
133+
* Provide migration guidance for APIs currently using mixed authentication
134+
* Document authentication patterns for development teams
135+
136+
Rollout Plan
137+
------------
138+
139+
1. Audit existing APIs and categorize by intended use case (external/internal/browser)
140+
2. Update global authentication configurations to prevent mixed authentication
141+
3. Refactor high-priority APIs to follow single-authentication patterns
142+
4. Create development guidelines and documentation for authentication choices
143+
5. Implement automated testing to validate authentication pattern compliance
144+
6. Monitor and enforce authentication patterns in code reviews
145+
146+
References
147+
==========
148+
149+
* Django REST Framework - Authentication and permissions
150+
* Django OAuth Toolkit documentation
151+
* Open edX Authentication Patterns Guide

0 commit comments

Comments
 (0)