@@ -2,7 +2,76 @@ Multi-factor Authentication
2
2
===========================
3
3
4
4
Piccolo Admin supports Multi-factor Authentication (MFA). See the
5
- ``mfa_providers `` argument in `` create_admin ` `.
5
+ ``mfa_providers `` argument in :func: ` create_admin <piccolo_admin.endpoints.create_admin> `.
6
6
7
- We currently recommend using the ``AuthenticatorProvider `` with
8
- ``XChaCha20Provider `` for encryption.
7
+ Most of the underlying functionality comes from ``piccolo_api ``.
8
+
9
+ ``MFAProvider ``
10
+ ---------------
11
+
12
+ We currently recommend using the :class: `AuthenticatorProvider <piccolo_api.mfa.authenticator.provider.AuthenticatorProvider> `
13
+ (which uses an authenticator app for generating codes) with
14
+ :class: `XChaCha20Provider <piccolo_api.encryption.providers.XChaCha20Provider> `
15
+ for encryption.
16
+
17
+ You can also implement your own subclass of :class: `MFAProvider <piccolo_api.mfa.provider.MFAProvider> `
18
+ if you want to do something custom.
19
+
20
+ Example
21
+ -------
22
+
23
+ .. code-block :: python
24
+
25
+ from piccolo_admin.endpoints import create_admin
26
+ from piccolo_api.encryption.providers import XChaCha20Provider
27
+ from piccolo_api.mfa.authenticator.provider import AuthenticatorProvider
28
+
29
+
30
+ app = create_admin(
31
+ ... ,
32
+ mfa_providers = [
33
+ AuthenticatorProvider(
34
+ encryption_provider = XChaCha20Provider(
35
+ encryption_key = (
36
+ b " my_encryption_key"
37
+ )
38
+ ),
39
+ )
40
+ ]
41
+ )
42
+
43
+ To generate the encryption key in the above example:
44
+
45
+ .. code-block :: pycon
46
+
47
+ >>> from piccolo_api.encryption.providers import XChaCha20Provider
48
+ >>> XChaCha20Provider.generate_key()
49
+ b'\xb7(\xa5\xa6\xa4&\xeb\x8eI\xfe_Y\x16\x12\xf4\xf4\xa8|\xc6#\xd1\x02\xa2s\x03]\xea\x12\xb9\xf1\xa2\xb3'
50
+
51
+ .. note ::
52
+ Piccolo Admin currently allows you to use a single ``MFAProvider ``, but
53
+ this might change in the future.
54
+
55
+ Install dependencies
56
+ --------------------
57
+
58
+ For the above example, you need to install some extra dependencies:
59
+
60
+ .. code-block :: bash
61
+
62
+ pip install piccolo_api[authenticator,pynacl]
63
+
64
+ Create database table
65
+ ---------------------
66
+
67
+ You need to create the database table for storing the MFA secrets, either by:
68
+
69
+ * Adding ``"piccolo_api.mfa.authenticator.piccolo_app" `` to your ``AppRegistry ``
70
+ in ``piccolo_conf.py ``, then running the migrations using
71
+ ``piccolo migrations forwards all ``.
72
+ * Manually creating the table.
73
+
74
+ .. code-block :: pycon
75
+
76
+ >>> from piccolo_api.mfa.authenticator.tables import AuthenticatorSecret
77
+ >>> AuthenticatorSecret.create_table().run_sync()
0 commit comments