You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add API (method in UserMixin) to enable fine-tuned two-factor requirements. (#1170)
Previously, whether two-factor authentication was required was controlled by SECURITY_TWO_FACTOR_REQUIRED and whether
the user had recently successfully performed a second factor authentication.
This default behavior hasn't changed - but now, all the authentication code calls UserMixin.check_tf_required() which, if
overridden in an application, can make the decision any way they want - for example - based on user group.
closes#1168
Copy file name to clipboardExpand all lines: docs/openapi.yaml
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -94,7 +94,7 @@ paths:
94
94
The user successfully signed in using their primary credential.
95
95
Note that depending on SECURITY_TWO_FACTOR configuration variable, a second form of authentication might be required prior to the user being fully authenticated.
96
96
`tf_required` will be set to True in this case.
97
-
Note that if 2FA is not configured, none of the ``tf_`` properties will be returned.
97
+
Note that if 2FA is not configured, only the ``tf_required`` property (=False) will be returned.
Copy file name to clipboardExpand all lines: docs/two_factor_configurations.rst
+10-2Lines changed: 10 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ Two-factor Configurations
4
4
Two-factor authentication provides a second layer of security to any type of
5
5
login, requiring extra information or a secondary device to log in, in addition
6
6
to ones login credentials. The added feature includes the ability to add a
7
-
secondary authentication method using either via email, sms message, or an
7
+
secondary authentication method using either an email link, sms message, or an
8
8
Authenticator app such as Google, Lastpass, or Authy.
9
9
10
10
The following code sample illustrates how to get started as quickly as
@@ -160,7 +160,7 @@ The Two-factor (2FA) API has four paths:
160
160
- Rescue
161
161
162
162
When using forms, the flow from one state to the next is handled by the forms themselves. When using JSON
163
-
the application must of course explicitly access the appropriate endpoints. The descriptions below describe the JSON access pattern.
163
+
the application must explicitly access the appropriate endpoints. The descriptions below is for the JSON access pattern.
164
164
165
165
Normal Login
166
166
~~~~~~~~~~~~
@@ -201,3 +201,11 @@ security of a two factor authentication but with a slightly better user experien
201
201
and clicking the 'Remember' button on the login form. Once the two factor code is validated, a cookie is set to allow skipping the validation step. The cookie is named
202
202
``tf_validity`` and contains the signed token containing the user's ``fs_uniquifier``. The cookie and token are both set to expire after the time delta given in
203
203
:py:data:`SECURITY_TWO_FACTOR_LOGIN_VALIDITY`. Note that setting ``SECURITY_TWO_FACTOR_LOGIN_VALIDITY`` to 0 is equivalent to ``SECURITY_TWO_FACTOR_ALWAYS_VALIDATE`` being ``True``.
204
+
205
+
Fine-Grained Control of Two-Factor
206
+
+++++++++++++++++++++++++++++++++++
207
+
The decision whether to require a second factor after primary authentication is made in :py:meth:`.UserMixin.check_tf_required`.
208
+
The default implementation returns True if :py:data:`SECURITY_TWO_FACTOR_REQUIRED` is set OR the user has a two-factor method already setup AND
209
+
and recent two-factor authentication isn't 'valid' (see above).
210
+
211
+
This method can be overridden in the applications User class. A common use case might be to require two-factor for any user with the 'admin' role.
0 commit comments