Commit 48e2e90
authored
MFA using an Authenticator app (#292)
* MFA prototype
* add mfa_providers abstract property
* flesh out email provider a bit more
* wip
* flesh out email some more, and add authenticator
* flesh out `AuthenticatorSeed` some more
* add method for fetching pyotp
* add `pyotp` to requirements
* add proper auth methods for pyotp
* start adding tests
* bump minimum Piccolo version
* test `create_new` method
* add qrcode logic from @sinisaos PR
* flesh out auth methods
* lazy load `qrcode`
* fleshing out logic some more in session login endpoint
* change imports
* make error messages consistent
* add TODO
* adding example app for testing
* add `AuthenticatorProvider` to example app
* added `get_registration_html` to provider
* rename `seed_table` to `secret_table`
* change params in `send_code` for authenticator
* Create README.md
* add `issuer_name` to `AuthenticatorProvider`
* fix typo in docstring
* add `get_registration_json`
* add `get_registration_json` to base class
* try embedding QR code image in HTML response
* flesh out `MFARegisterEndpoint` endpoint
* add todo about primary key
* fix bugs in register endpoint
* fix error - was returning html instead of json
* show MFA code input on login page
* Update README.md
* Update tests.yaml
* fix some linter errors
* add `device_name` column to `AuthenticatorSecret`
* make sure each provider has a custom token name
* make each MFA Provider have a unique token name
This means we can potentially put several MFA providers on the login page
* If the user reused a code make sure auth fails (could be a replay attack)
* add auth test for replay attacks
* add `generate_recovery_code`
* store recovery codes, and return recovery codes in endpoints (taken from @sinisaos example)
* make sure recovery codes can be used to login
* ignore mypy warnings for now
* install pyotp in CI
* endpoint test WIP
* update `TestMFARegisterEndpoint`
* remove todo
* encrypt secret in db
* use a proper template for MFA sign up
* add links for where to download the authenticator app, and add JS for copying to clipboard
* also test HTML register endpoint
* add playwright tests
* require a password to enable MFA
* fix test
* create separate template for cancelling MFA
* initial docs
* improve docs for AuthenticatorProvider params
* add docs for tables
* rename `mfa_register_endpoint` to `mfa_setup`
So the name is more consistent with other endpoints in `piccolo_api`
* improve docs, and rename from register to setup
* remove debugging
* improve template when MFA is disabled
* add re-enabled link on disabled template
* fix linter errors
* use `self._auth_table`
* render cancel template in GET endpoint if user is already enrolled
* remove email for now
* remove email from README
* start moving encryption into its own file
* update code to use encryption provider
* improve the docstring for `mfa_setup` - mention rate limiting
* improve docstrings
* add params to docstrings
* remove `device_name` - not currently used
* change `revoke_all` to `revoke`
The current design assumes a single device per user
* add `XChaCha20Provider`
* make sure pynacl is installed in tests
* make sure pynacl is installed in tests (continued)
* improve coverage
* add `TestRevoke`
* add a test to make sure auth works
* remove unused import
* add tests for recovery codes
* remove breakpoint
* fix bug with prefix
* simplify encoding
* changed login logic for multiple MFA providers
* make `mfa_provider_name` param optional if there's only a single MFA provider
* add `help_text` to `revoked_at`
* add `valid_window` argument to `AuthenticatorProvider`
* tell the user whether we sent them a code
* increase coverage for `AuthenticatorSecret`
* remove TODO in endpoint test
* add tests for generating recovery codes
* fix path to `AuthenticatorProvider` in docstring
* add docs for encryption
* remove imports
* add docstring and type annotations to `get_b64encoded_qr_image`1 parent cd4a8f4 commit 48e2e90
File tree
58 files changed
+2318
-9
lines changed- .github/workflows
- docs/source
- encryption
- mfa
- images
- e2e
- example_projects
- mfa_demo
- templates
- piccolo_api
- encryption
- mfa
- authenticator
- piccolo_migrations
- session_auth
- templates
- requirements
- extras
- scripts
- tests/mfa
- authenticator
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
58 files changed
+2318
-9
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
24 | 27 | | |
25 | 28 | | |
26 | 29 | | |
| |||
59 | 62 | | |
60 | 63 | | |
61 | 64 | | |
| 65 | + | |
| 66 | + | |
62 | 67 | | |
63 | 68 | | |
64 | 69 | | |
| |||
86 | 91 | | |
87 | 92 | | |
88 | 93 | | |
| 94 | + | |
| 95 | + | |
89 | 96 | | |
90 | 97 | | |
91 | 98 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| 29 | + | |
29 | 30 | | |
30 | 31 | | |
31 | 32 | | |
| |||
35 | 36 | | |
36 | 37 | | |
37 | 38 | | |
| 39 | + | |
38 | 40 | | |
39 | 41 | | |
40 | 42 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
Loading
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
0 commit comments