Two-factor authentication plugin for Tutor
Adds authenticator-app 2FA to Open edX login, with QR enrollment, one-time
recovery codes, and access checks for LMS and Studio. The plugin installs
django-two-factor-auth
and the bundled Open edX integration in the Open edX image.
Targets Tutor 22 / Open edX Verawood. Role-based enforcement is available from version 1.0.0. See the configuration section when upgrading from 0.1.0.
Installation
Install in the same Python environment as Tutor:
pip install tutor-contrib-2fa==1.0.4
No separate integration package or manual settings plugin is needed.
Usage
tutor plugins enable 2fa
tutor config save
tutor images build openedx
For an existing development environment:
tutor images build openedx-dev
tutor dev stop lms cms
tutor dev do init -l 2fa
tutor dev start -d lms cms
Open http://<lms-host>:8000/2fa/. Keep the authentication MFE running if your
installation uses it. For a new environment, use tutor dev launch after building;
the normal initialization runs the OTP migrations automatically.
For staging or production, configure your public hostnames and HTTPS first. Back up the database and activate during a maintenance window:
tutor config save --set ENABLE_HTTPS=true
tutor local stop lms cms lms-worker cms-worker
tutor local do init -l 2fa
tutor local start -d lms cms lms-worker cms-worker
Use the same reviewed plugin version and image on staging and production. Full production deployment has not yet been validated.
Test the login
- Sign in as a user in a required role (admin or staff by default), scan the QR code with an authenticator app, and enter its current code.
- Setup opens the recovery-code page. Click Generate recovery codes, use Copy codes to save them, then click Continue to reach your original destination. Continue stays disabled until copying succeeds and the server records the acknowledgement. Sign out and sign in again; an OTP should be required.
- Check that a wrong OTP is rejected and a recovery code works only once.
- Sign in as an ordinary user without a required role; login should not ask for 2FA.
- Check Studio/admin access and your SSO/API workflows on staging.
Keep phone and server clocks synchronized. Keep QR secrets and recovery codes private.
For an automated check on local or staging:
tutor dev exec lms ./manage.py lms two_factor_check --live
Use tutor local exec on staging. The command creates a temporary platform staff account,
checks login/enrollment/recovery, and deletes it even if a check fails.
This automated check requires staff in the required roles list.
The configured LMS URL must be reachable from the command's container.
Configuration
Use these two settings in Tutor's config.yml:
ENABLE_2FA: true
TWO_FACTOR_AUTHENTICATION_REQUIRED_ROLES:
- admin
- staff
These are the defaults. Add instructor and/or student to require 2FA for them too.
| Role | Who matches |
|---|---|
admin |
Superusers (is_superuser). |
staff |
Platform staff (is_staff). |
instructor |
Users with course or organization instructor or staff access. |
student |
Users with at least one active course enrollment. |
| Custom name | An existing course/organization role or Django group with that exact name. |
A match on any role requires setup and 2FA at sign-in. These roles apply across
the account, not just while visiting a particular course. A newly registered user
without an active enrollment does not yet match student.
No match means normal login, even if the user previously enrolled an authenticator.
Existing devices and recovery codes are kept, but new enrollment is unavailable
for exempt users. An empty list ([]) requires 2FA for nobody. Role changes are
checked on subsequent browser requests and during the Studio SSO handoff.
Use the lowercase names shown above for built-in roles. Custom names are case-sensitive and must already exist as roles or groups; adding a name does not create permissions. Built-in names keep the definitions above, even if a Django group has the same name. A typo in a custom name matches nobody, so test the intended account after changing the list.
Let an OAuth application read a user's account
While 2FA is on, the LMS refuses every API call that carries a bearer token but no browser
session. That includes a storefront server that signed a user in with the LMS and then reads their
name and e-mail (GET /api/user/v1/accounts/<username>): the login works, the lookup fails with
403 mfa_required.
To allow this for specific applications, list their OAuth application names:
TWO_FACTOR_AUTHENTICATION_BEARER_APPLICATIONS:
- payload-admin
The default is an empty list, which keeps every bearer call blocked. A call is allowed only when all of these hold:
- the token was issued by a listed application through the authorization-code flow, so the browser login, including 2FA for users the policy covers, had already happened;
- the request is a
GETorHEADfor exactly/api/user/v1/accounts/<username>; - the token is still valid and belongs to the user who passed 2FA, and for users the policy covers the confirmed authenticator device is still there.
The proof is kept in the shared cache for the lifetime of the token. After a cache loss the call is blocked again and the user has to sign in again. The setting applies to the LMS only.
After editing the policy:
tutor config save
tutor local restart lms cms lms-worker cms-worker
For development, use tutor dev restart lms cms. Policy changes do not need an
image rebuild after this plugin version is installed in the image.
To disable enforcement for everyone:
tutor config save --set ENABLE_2FA=false
tutor local restart lms cms lms-worker cms-worker
Set it back to true to enforce the configured roles again.
Upgrading: rename TWO_FACTOR_AUTH_ENABLED (or the older TWO_FACTOR_ENABLED)
to ENABLE_2FA in config.yml, preserving its value, and remove the old key.
The plugin rejects obsolete enable keys to prevent a previously disabled setup
from silently becoming enabled. The former all-user policy is replaced by the
admin/staff default; set the required role list explicitly for your installation.
The proposed ONLY_* and OPTIONAL_FOR_USERS flags are not used.
The dependency version remains a separate build setting:
| Setting | Default | Description |
|---|---|---|
TWO_FACTOR_AUTH_VERSION |
1.18.1 |
Version of django-two-factor-auth installed in the image. |
To upgrade the authenticator library without changing the plugin code:
tutor config save --set TWO_FACTOR_AUTH_VERSION=<version>
tutor images build openedx
Replace <version> with the exact release you want. For development, also rebuild
openedx-dev. Then repeat the stop, migrate and start commands above for your
environment. Test the selected version on staging before production use.
Let a token-protected API path through
Some APIs are called by a service with its own shared token and no browser session, for example the Heartbeat
platform health API. The gate would answer mfa_required for them. List the exact paths in config.yml:
TWO_FACTOR_AUTHENTICATION_TOKEN_PATHS:
- /api/platform_health/v1/summary
The default is an empty list, so every /api/ call stays blocked. A call is let through only when all of these hold:
- the method is
GET, - the path is exactly one of the listed paths (no wildcards, no sub-paths),
- the request carries an
Authorization: Bearer <token>header.
The gate does not check that token. The listed view must check it itself and refuse requests without it.
Only list paths of views that do that. Other Tutor plugins may add their own paths to this list in their LMS settings patch; the plugin merges them with the list above.
Run tutor config save and rebuild or restart the LMS after changing the list.
Scope
- Browser-session TOTP only; FIDO2/passkeys, optional enrollment and invitation codes are not included.
- Studio SSO supports authorization codes issued after the LMS role check and, for required roles, MFA. OAuth Toolkit still validates client credentials, redirect URIs, PKCE and code expiry/replay. Studio receives the policy result and verified device through a short-lived server-side proof and records it in its own session; browser cookies are not forwarded to the token endpoint.
- LMS workers and Studio must use the same shared default Django cache (Tutor's Redis default cache). Authorization proof expires with the code; Studio's session handoff expires after 60 seconds. Cache loss fails closed: restart Studio sign-in. Codes issued before this update must also be replaced by restarting sign-in.
- Other non-browser API/token requests without a verified session are rejected; mobile, service clients and refresh-token grants need separate validation.
- First enrollment accepts an existing authenticated session; agree a reauthentication and recovery policy before production rollout.
- MFA is a step in the existing browser login: after verification the plugin
resumes the platform-selected destination, including
finish_auth, course links and Studio authorization. Destinations use Open edX'sLOGIN_REDIRECT_WHITELISTand are bound to the signing-in user. Configure approved MFE hosts there as usual. - A verified LMS session keeps using the normal login redirects and JWT refresh; moving between MFEs does not require another OTP. Studio's separate session is verified through LMS OAuth. This is SSO, not a shared cookie across arbitrary domains, and does not change Open edX's session expiry or logout semantics.
- Email verification and password reset remain Open edX features.
Development
git clone git@github.com:Abstract-Tech/tutor-contrib-2fa.git
cd tutor-contrib-2fa
python3 -m venv .venv
source .venv/bin/activate
pip install -e '.[dev]' -e ./tutor2fa/backend
make test
make build
make build creates and checks distributions; it does not publish them. The
backend is bundled with this plugin, not published separately. Keep its version
in sync with tutor2fa/__about__.py.
Scaffold generated from
overhangio/cookiecutter-tutor-plugin
at commit 5d664b0f3436f375e22be789a4aaef445c3532d2.
Publishing
Version 0.1.0 was the first PyPI release. For 1.0.0, the old pre-PyPI
v1.0.0 Git tag was replaced to point to the role-based enforcement release.
Using the TestPyPI account that should own this package, add a pending publisher at https://test.pypi.org/manage/account/publishing/:
| Field | Value |
|---|---|
| Project name | tutor-contrib-2fa |
| GitHub owner | Abstract-Tech |
| Repository | tutor-contrib-2fa |
| Workflow | release.yml |
| Environment | testpypi |
The GitHub owner does not automatically assign PyPI account or organization ownership. Configure the publisher from the intended owning account.
Push a version tag matching both package versions to trigger publishing:
git tag -a v1.0.2 -m "Release 1.0.2"
git push origin v1.0.2
Create the tag only once. For later releases, update both package versions and use a new matching tag. The workflow checks the versions, tests and builds the package, publishes to TestPyPI with OIDC, and checks installation from TestPyPI. Only after that check succeeds does it publish the same distribution artifacts to production PyPI, without rebuilding them.
Configure both publishers before pushing a release tag. On production PyPI, use
https://pypi.org/manage/account/publishing/ with the same project, owner,
repository and workflow values above, but set the environment to pypi.
Existing tags retain their original workflow. Do not move an existing release tag.
To test installation manually in a fresh virtual environment:
python -m pip install 'tutor>=22,<23' 'packaging>=23'
python -m pip install --no-deps --index-url https://test.pypi.org/simple/ tutor-contrib-2fa==1.0.4
python -m pip check
tutor plugins list
Dependencies come from PyPI; only this plugin comes from TestPyPI. Do this after the upload succeeds. TestPyPI accounts and publishers are separate from PyPI. An already uploaded version cannot be overwritten; use a new version for changes.
Recovery code policy
Recovery setup is required: generate codes, then use Copy codes. Continue remains disabled until the server records that action. If the tab is closed, setup resumes after the next 2FA login. Existing generated codes are shown again while setup is incomplete; they are not regenerated automatically.
The completion state is stored per account, not in the browser. Protected pages, API access and login completion remain gated until it is saved. Each new code set requires a new acknowledgement; a stale tab cannot acknowledge a replacement set. Users already enrolled when this update is installed must save their codes once, because previous versions did not record this action. Existing codes remain valid.
A verified 2FA session is required, but there is no extra authenticator prompt. Replacement still requires confirmation and immediately invalidates old codes. Each recovery code can be used once. Codes remain accessible through Account Security after setup. Run the plugin init migrations during installation/upgrade.
Completion records a successful clipboard copy, not proof that the user stored the codes elsewhere. JavaScript is required for this control.
License
This software is licensed under the terms of the AGPLv3 (AGPL-3.0-only).
Metadata
Release files for tutor-contrib-2fa 1.0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| tutor_contrib_2fa-1.0.4.tar.gz | 328.2 kB | With provenance | Details for tutor_contrib_2fa-1.0.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| tutor_contrib_2fa-1.0.4-py3-none-any.whl | Python 3 | none | any | Details for tutor_contrib_2fa-1.0.4-py3-none-any.whl |
Total release size: 1.1 MB
Release files / tutor_contrib_2fa-1.0.4.tar.gz
| Download URL | tutor_contrib_2fa-1.0.4.tar.gz |
|---|---|
| Size | 328.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ba1aba1bdd91ecaf8e919b2d7603f84072f959631fe20017e17ac2198d44008d
|
|
BLAKE2b-256 checksum How to use checksums |
b4bef9c549d21ba6847383de875c9d7fcd6c45659eff55054afff201de54a55b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.
Transparency logRelease files / tutor_contrib_2fa-1.0.4-py3-none-any.whl
| Download URL | tutor_contrib_2fa-1.0.4-py3-none-any.whl |
|---|---|
| Size | 762.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fe80cfd9249d19a1857453f34b85cd4fd150459d1a462203b042bc47bc863c3c
|
|
BLAKE2b-256 checksum How to use checksums |
b5ace5e62dbdf4ac55c8651b64740e7b32557256193cff9b635a6c41d4d43bcf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.
Transparency logSecurity for tutor-contrib-2fa 1.0.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for tutor_contrib_2fa-1.0.4.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.