Skip to main content

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.2

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

  1. 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.
  2. 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.
  3. Check that a wrong OTP is rejected and a recovery code works only once.
  4. Sign in as an ordinary user without a required role; login should not ask for 2FA.
  5. 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.

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.

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's LOGIN_REDIRECT_WHITELIST and 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.2
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.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tutor-contrib-2fa 1.0.2
File Size Uploaded Provenance Actions
tutor_contrib_2fa-1.0.2.tar.gz 321.7 kB With provenance Details for tutor_contrib_2fa-1.0.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for tutor-contrib-2fa 1.0.2
File Interpreter ABI Platform Actions
tutor_contrib_2fa-1.0.2-py3-none-any.whl Python 3 none any Details for tutor_contrib_2fa-1.0.2-py3-none-any.whl

Total release size: 1.1 MB

Release files / tutor_contrib_2fa-1.0.2.tar.gz

Download URL tutor_contrib_2fa-1.0.2.tar.gz
Size 321.7 kB
Tags Source
SHA-256 checksum
How to use checksums
ffa645f5dad11df92f361f8c586793afa8b53c29a3b7d644e49e1d75fed81e19
BLAKE2b-256 checksum
How to use checksums
9c6235b79ade9c07415addd46a2b6d49b6691d4421d31fd0193e540c63d1ff87
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 18, 2026.

Transparency log

Release files / tutor_contrib_2fa-1.0.2-py3-none-any.whl

Download URL tutor_contrib_2fa-1.0.2-py3-none-any.whl
Size 758.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a85c724351a8bc4f4f7de4542b8d613b20f7e42e7db662098a2cfae6ce13fda1
BLAKE2b-256 checksum
How to use checksums
f244027a2304787a646ceb7b636799fa2b5bf084a14d2572c27d05dfc27ae148
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 18, 2026.

Transparency log

Security for tutor-contrib-2fa 1.0.2

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.

Select from 2 files

Attestation for tutor_contrib_2fa-1.0.2.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 18, 2026.

Transparency log

A 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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page