Debian Codegraph @

docs/configuration.rst

raw
1 Configuration
2 =============
3
4 .. warning::
5 Be sure to set all configuration (in app.config["xxx"]) *PRIOR* to instantiating
6 the Security class or calling security.init_app().
7
8 The following configuration values are used by Flask-Security:
9
10 Core
11 --------------
12
13 These configuration keys are used globally across all features.
14
15 .. py:data:: SECRET_KEY
16
17 This is actually part of Flask - but is used by Flask-Security to sign all tokens.
18 It is critical this is set to a strong value. For python3 consider using: ``secrets.token_urlsafe()``
19
20 .. py:data:: SECRET_KEY_FALLBACKS
21
22 This is part of Flask (>=3.1) but can be used by Flask-Security to unsign tokens.
23 See Flask documentation https://flask.palletsprojects.com/en/stable/config/#SECRET_KEY_FALLBACKS
24
25 .. versionadded:: 5.6.0
26
27 .. py:data:: SECURITY_BLUEPRINT_NAME
28
29 Specifies the name for the Flask-Security blueprint.
30
31 Default: ``"security"``.
32
33 .. py:data:: SECURITY_URL_PREFIX
34
35 Specifies the URL prefix for the Flask-Security blueprint.
36
37 Default: ``None``.
38
39 .. py:data:: SECURITY_STATIC_FOLDER
40
41 Specifies the folder name for static files (webauthn).
42
43 Default: ``"static"``.
44
45 .. versionadded:: 5.1.0
46
47 .. py:data:: SECURITY_STATIC_FOLDER_URL
48
49 Specifies the URL for static files used by Flask-Security (webauthn).
50 See Flask documentation https://flask.palletsprojects.com/en/latest/blueprints/#static-files
51
52 Default: ``"/fs-static"``.
53
54 .. versionadded:: 5.1.0
55
56 .. py:data:: SECURITY_SUBDOMAIN
57
58 Specifies the subdomain for the Flask-Security blueprint. If your authenticated
59 content is on a different subdomain, also enable :py:data:`SECURITY_REDIRECT_ALLOW_SUBDOMAINS`.
60
61 Default: ``None``.
62 .. py:data:: SECURITY_FLASH_MESSAGES
63
64 Specifies whether or not to flash messages for actions certain endpoint perform.
65 Normally Flash-Security views will flash informational or error messages only when the operation
66 results in a redirect.
67
68 Default: ``True``.
69 .. py:data:: SECURITY_INPUT_NORMALIZE_FORM
70
71 Forms that take unstructured strings (e.g. username, webauthn name)
72 are sanitized (using nh3), validated for specific unicode categories
73 and optionally normalized using Python unicodedata.normalize() method
74
75 Default: ``"NFKD"``
76
77 .. versionadded:: 5.9.0
78 .. py:data:: SECURITY_I18N_DOMAIN
79
80 Specifies the name for domain used for translations.
81
82 Default: ``"flask_security"``
83 .. py:data:: SECURITY_I18N_DIRNAME
84
85 Specifies the directory containing the ``MO`` files used for translations.
86 When using flask-babel this can also be a list of directory names - this
87 enables application to override a subset of messages if desired. The
88 default ``builtin`` uses translations shipped with Flask-Security.
89
90 Default: ``"builtin"``.
91
92 .. versionchanged:: 5.2.0
93 "builtin" is a special name which will be interpreted as the ``translations``
94 directory within the installation of Flask-Security.
95
96 .. py:data:: SECURITY_TOKEN_AUTHENTICATION_KEY
97
98 Specifies the query string parameter to read when using token authentication.
99
100 Default: ``"auth_token"``.
101
102 .. py:data:: SECURITY_TOKEN_AUTHENTICATION_HEADER
103
104 Specifies the HTTP header to read when using token authentication.
105
106 Default: ``"Authentication-Token"``.
107
108 .. py:data:: SECURITY_TOKEN_MAX_AGE
109
110 Specifies token expiration as a timedelta. Setting to 0 will mean the
111 token never expires.
112
113 Default: ``timedelta(minutes=15)``
114
115 .. versionchanged:: 5.9.0
116 Change from int to a timedelta. If an int is provided, it will be
117 changed to a timedelta as part of Flask-Security initialization.
118
119 .. py:data:: SECURITY_TOKEN_EXPIRE_TIMESTAMP
120
121 A callable that returns a unix timestamp in the future when this specific
122 authentication token should expire. Returning 0 means no expiration.
123 It is passed the currently authenticated User so any fields can be used
124 to customize an expiration time. Of course it is called in a request
125 context so any information about the current request can also be used.
126
127 If BOTH this and :data:`SECURITY_TOKEN_MAX_AGE` are set - the shorter is used.
128
129 .. note::
130 These 2 expiry options work differently - with this one, the actual expire
131 timestamp is in the auth_token. The signed token (using itsdangerous)
132 has the timestamp the token was generated. On validation, that is checked
133 against ``SECURITY_TOKEN_MAX_AGE``. So for MAX_AGE, at the time of
134 validation, the token hasn't yet been associated with a User.
135
136 Default: ``lambda user: 0``
137
138
139 .. py:data:: SECURITY_CACHE_CONTROL
140
141 Specifies the Cache-Control header attributes to be sent with all responses from Flask-Security endpoints.
142 Each entry in the dict is a (attribute, value) pair, where allowed attributes are
143 defined in the Flask documentation https://flask.palletsprojects.com/en/stable/api/#flask.Response.cache_control.
144
145 .. note::
146 Flask-Security does not pretend to handle the Cache-Control header for your application.
147 This default setting is to ensure that out of the box, Flask-Security responses
148 which might contain sensitive information aren't cached.
149 Please see https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Cache-Control#cache_directives.
150 Responses from your own application endpoints (including endpoints protected with
151 a Flask-Security decorator, such as token-authenticated APIs) are not modified -
152 set the Cache-Control header there yourself if needed.
153
154 .. note::
155 Flask itself adds the 'Vary: Cookie' header to all responses that access the session (cookie).
156 This of course includes all non-anonymous Flask-Security endpoints as well as
157 any application endpoints that are decorated with a Flask-Security decorator.
158 This alone is likely enough to ensure no personal information is leaked.
159
160
161 Default: ``{"private": True, "no-store": True}``.
162
163 .. versionadded:: 5.8.0
164
165 .. py:data:: SECURITY_EMAIL_VALIDATOR_ARGS
166
167 Email address are validated and normalized via the ``mail_util_cls`` which
168 defaults to :class:`.MailUtil`. That uses the `email_validator`_ package whose methods
169 have configurable options - these can be set here and will be passed in.
170 For example setting this to: ``{"check_deliverability": False}`` is useful
171 when unit testing if the emails are fake.
172
173 ``mail_util_cls`` has 2 methods - ``normalize`` and ``validate``. Both
174 ensure the passed value is a valid email address, and returns a normalized
175 version. ``validate`` additionally, by default, verifies that the email
176 address can likely actually receive an email.
177
178 Default: ``None``, meaning use the defaults from email_validator package.
179
180 .. versionadded:: 4.0.0
181
182 .. _email_validator: https://pypi.org/project/email-validator/
183
184 .. py:data:: SECURITY_DEFAULT_HTTP_AUTH_REALM
185
186 Specifies the default authentication realm when using basic HTTP auth.
187
188 Default: ``Login Required``
189
190 .. py:data:: SECURITY_REDIRECT_BEHAVIOR
191
192 Passwordless login, confirmation, reset password, unified signin, change_email, and Social Login
193 have GET endpoints that validate the passed token and redirect to an action form.
194 For Single-Page-Applications style UIs which need to control their own internal URL routing these redirects
195 need to not contain forms, but contain relevant information as query parameters.
196 Setting this to ``"spa"`` will enable that behavior.
197
198 When this is enabled, the following must also be defined:
199
200 - :py:data:`SECURITY_POST_OAUTH_LOGIN_VIEW` (if :py:data:`SECURITY_OAUTH_ENABLE` is True)
201 - :py:data:`SECURITY_POST_OAUTH_VERIFY_VIEW` (if :py:data:`SECURITY_OAUTH_ENABLE` is True)
202 - :py:data:`SECURITY_VERIFY_ERROR_VIEW` (if :py:data:`SECURITY_OAUTH_ENABLE` is True)
203 - :py:data:`SECURITY_LOGIN_ERROR_VIEW`
204 - :py:data:`SECURITY_CONFIRM_ERROR_VIEW` (if :py:data:`SECURITY_CONFIRMABLE` is True)
205 - :py:data:`SECURITY_POST_CHANGE_EMAIL_VIEW` (if :py:data:`SECURITY_CHANGE_EMAIL` is True)
206 - :py:data:`SECURITY_CHANGE_EMAIL_ERROR_VIEW` (if :py:data:`SECURITY_CHANGE_EMAIL` is True)
207 - :py:data:`SECURITY_POST_CONFIRM_VIEW` (if :py:data:`SECURITY_CONFIRMABLE` is True)
208 - :py:data:`SECURITY_RESET_ERROR_VIEW` (if :py:data:`SECURITY_RECOVERABLE` is True)
209 - :py:data:`SECURITY_RESET_VIEW` (if :py:data:`SECURITY_RECOVERABLE` is True)
210
211
212 Default: ``None`` which is existing html-style form redirects.
213
214 .. versionadded:: 3.3.0
215
216 .. py:data:: SECURITY_REDIRECT_HOST
217
218 Mostly for development purposes, the UI is often developed
219 separately and is running on a different port than the
220 Flask application. In order to test redirects, the `netloc`
221 of the redirect URL needs to be rewritten. Setting this to e.g. `localhost:8080` does that.
222
223 .. tip::
224 Be aware that when this is set, any of the `*_VIEW` configuration variables that are set
225 to URLs and not endpoints, will be redirected to this host.
226
227 Default: ``None``.
228
229 .. versionadded:: 3.3.0
230
231 .. py:data:: SECURITY_REDIRECT_ALLOW_SUBDOMAINS
232
233 If ``True`` then subdomains (and the root domain) of the top-level host set
234 by Flask's ``SERVER_NAME`` configuration will be allowed as post-view redirect targets.
235 This is beneficial if you wish to place your authentication on one subdomain and
236 authenticated content on another, for example ``auth.domain.tld`` and ``app.domain.tld``.
237
238 Default: ``False``.
239
240 .. versionadded:: 4.0.0
241
242 .. py:data:: SECURITY_REDIRECT_BASE_DOMAIN
243
244 Set the base domain for checking allowable redirects. The intent here is to
245 allow an application to be served on e.g. "flaskapp.my.org" and redirect
246 to "myservice.my.org" (which maybe isn't a Flask app). Flask's SERVER_NAME
247 can't be used to verify redirects in this case. Note that in most cases
248 the application will want to set Flask's SESSION_COOKIE_DOMAIN to be this base domain -
249 otherwise authorization information won't be sent.
250
251 Default: ``None``
252
253 .. versionadded:: 5.5.0
254
255 .. py:data:: SECURITY_REDIRECT_ALLOWED_SUBDOMAINS
256
257 A list of subdomains. Each will be prepended to
258 ``SECURITY_REDIRECT_BASE_DOMAIN`` and checked against the requested redirect.
259 If the list includes '.', the base domain itself will be checked against the redirect.
260
261 Default: ``[]``
262
263 .. versionadded:: 5.5.0
264
265 .. versionchanged:: 5.9.0
266 Add support for using '.' to signify checking against the base domain value itself.
267
268
269 .. note::
270 The above 4 config options apply BOTH to the handling of ``next`` parameter
271 as well as all the ``XXX_VIEW`` URL configuration options
272 for those views that perform a redirect after processing.
273
274 .. py:data:: SECURITY_CSRF_PROTECT_MECHANISMS
275
276 Authentication mechanisms that require CSRF protection.
277 These are the same mechanisms as are permitted in the ``@auth_required`` decorator.
278
279 Default: ``("basic", "session", "token")``.
280
281 .. py:data:: SECURITY_CSRF_IGNORE_UNAUTH_ENDPOINTS
282
283 If ``True`` then CSRF will not be required for endpoints
284 that don't require authentication (e.g. login, logout, register, forgot_password).
285
286 Default: ``False``.
287
288 .. py:data:: SECURITY_CSRF_COOKIE_NAME
289
290 The name for the CSRF cookie. This usually should be dictated by your
291 client-side code - more information can be found at :ref:`csrf_topic`
292
293 Default: ``None`` - meaning no cookie will be sent.
294
295 .. py:data:: SECURITY_CSRF_COOKIE
296
297 A dict that defines the parameters required to
298 set a CSRF cookie.
299 The complete set of parameters is described in Flask's `set_cookie`_ documentation.
300
301 Default: ``{"samesite": "Strict", "httponly": False, "secure": True}``
302
303 .. versionchanged:: 4.1.0
304 The 'key' attribute was deprecated in favor of a separate configuration
305 variable :data:`SECURITY_CSRF_COOKIE_NAME`.
306
307 .. versionchanged:: 5.9.0
308 ``secure`` default changed to ``True``
309
310 .. py:data:: SECURITY_CSRF_HEADER
311
312 The HTTP Header name that will contain the CSRF token. ``X-XSRF-Token``
313 is used by packages such as `axios`_.
314
315 Default: ``"X-XSRF-Token"``.
316
317 .. py:data:: SECURITY_CSRF_COOKIE_REFRESH_EACH_REQUEST
318
319 By default, csrf_tokens have an expiration (controlled
320 by the configuration variable ``WTF_CSRF_TIME_LIMIT``.
321 This can cause CSRF failures if say an application is left
322 idle for a long time. You can set that time limit to ``None``
323 or have the CSRF cookie sent on every request (which will give
324 it a new expiration time).
325
326 Default: ``False``.
327
328 .. py:data:: SECURITY_SCRIPT_NONCE_KEY
329
330 If set, adds a nonce attribute to all ``<script>`` tags rendered by Flask-Security.
331 The nonce itself needs to be placed in the flask ``g`` context under the key defined here.
332 This is useful when the Content Security Policy requires a nonce on script tags like::
333
334 Content-Security-Policy: script-src 'nonce-{g.your-key}'
335
336 Default: ``None``.
337
338 .. versionadded:: 5.7.0
339
340 .. py:data:: SECURITY_EMAIL_SENDER
341
342 Specifies the email address to send emails as.
343
344 Default: value set to ``MAIL_DEFAULT_SENDER`` if Flask-Mail is used otherwise ``no-reply@localhost``.
345
346 .. py:data:: SECURITY_USER_IDENTITY_ATTRIBUTES
347
348 Specifies which attributes of the user object can be used for credential validation.
349
350 Defines the order and matching that will be applied when validating login
351 credentials (either via standard login form or the unified sign in form).
352 The identity field in the form will be matched in order using this configuration
353 - the FIRST match will then be used to look up the user in the DB.
354
355 Mapping functions take a single argument - ``identity`` from the form
356 and should return ``None`` if the ``identity`` argument isn't in a format
357 suitable for the attribute. If the ``identity`` argument format matches, it
358 should be returned, optionally having had some normalization performed.
359 The returned result will be used to look up the identity in the UserDataStore
360 using the column name specified in the key.
361
362 The provided :meth:`flask_security.uia_phone_mapper` for example performs
363 phone number normalization using the ``phonenumbers`` package.
364
365 .. tip::
366 If your mapper performs any sort of normalization,
367 make sure you apply the exact same transformation in your form validator
368 when setting the field.
369
370 .. danger::
371 Make sure that any attributes listed here are marked Unique in your UserDataStore
372 model.
373
374 .. danger::
375 Make sure your mapper methods guard against malicious user input. For example,
376 if you allow ``username`` as an identity method you could use `nh3`_::
377
378 def uia_username_mapper(identity):
379 # we allow pretty much anything - but we sanitize it.
380 # tags=set() strips all HTML tags rather than allowing nh3's defaults.
381 return nh3.clean(identity, tags=set())
382
383 Default::
384
385 [
386 {"email": {"mapper": uia_email_mapper, "case_insensitive": True}},
387 ]
388
389 If you enable :py:data:`SECURITY_UNIFIED_SIGNIN` and set ``sms`` as a :py:data:`SECURITY_US_ENABLED_METHODS`
390 and your `SECURITY_USER_IDENTITY_ATTRIBUTES` contained::
391
392 [
393 {"email": {"mapper": uia_email_mapper, "case_insensitive": True}},
394 {"us_phone_number": {"mapper": uia_phone_mapper}},
395 ]
396
397 Then after the user sets up their SMS - they could login using their phone number and
398 get a text with the authentication code.
399
400 .. versionchanged:: 4.0.0
401 Changed from list to list of dict.
402
403 .. _nh3: https://pypi.org/project/nh3/
404
405 .. py:data:: SECURITY_USER_IDENTITY_MAPPINGS
406
407 .. versionadded:: 3.4.0
408 .. deprecated:: 4.0.0
409 Superseded by :py:data:`SECURITY_USER_IDENTITY_ATTRIBUTES`
410
411 .. py:data:: SECURITY_API_ENABLED_METHODS
412
413 Various endpoints of Flask-Security require the caller to be authenticated.
414 This variable controls which of the methods - ``token``, ``session``, ``basic``
415 will be allowed. The default does NOT include ``basic`` since if ``basic``
416 is in the list, and if the user is NOT authenticated, then the standard/required
417 response of 401 with the ``WWW-Authenticate`` header is returned. This is
418 rarely what the client wants.
419
420 Default: ``["session", "token"]``.
421
422 .. versionadded:: 4.0.0
423
424 .. py:data:: SECURITY_DEFAULT_REMEMBER_ME
425
426 Specifies the default "remember me" value used when logging in a user.
427
428 Default: ``False``.
429
430 .. py:data:: SECURITY_RETURN_GENERIC_RESPONSES
431
432 If set to ``True`` Flask-Security will return generic responses to endpoints
433 that could be used to enumerate users. Please see :ref:`generic_responses`.
434
435 Default: ``False``
436
437 .. versionadded:: 5.0.0
438
439 .. py:data:: SECURITY_FRESHNESS
440
441 A timedelta used to protect endpoints that alter sensitive information.
442 This is used to protect the following Flask Security endpoints:
443
444 - :py:data:`SECURITY_US_SETUP_URL`
445 - :py:data:`SECURITY_TWO_FACTOR_SETUP_URL`
446 - :py:data:`SECURITY_WAN_REGISTER_URL`
447 - :py:data:`SECURITY_WAN_DELETE_URL`
448 - :py:data:`SECURITY_MULTI_FACTOR_RECOVERY_CODES`
449 - :py:data:`SECURITY_CHANGE_EMAIL_URL`
450 - :py:data:`SECURITY_CHANGE_USERNAME_URL`
451
452 This can also be used to protect application endpoints with the :meth:`flask_security.auth_required` decorator.
453
454 Setting this to a negative number will disable any freshness checking and
455 the endpoints:
456
457 - :py:data:`SECURITY_VERIFY_URL`
458 - :py:data:`SECURITY_US_VERIFY_URL`
459 - :py:data:`SECURITY_US_VERIFY_SEND_CODE_URL`
460 - :py:data:`SECURITY_WAN_VERIFY_URL`
461 - :py:data:`SECURITY_OAUTH_VERIFY_START_URL`
462 - :py:data:`SECURITY_OAUTH_VERIFY_RESPONSE_URL`
463
464 won't be registered.
465 Setting this to 0 results in undefined behavior.
466 Please see :meth:`flask_security.check_and_update_authn_fresh` for details.
467
468 .. note::
469 The timestamp of when the caller/user last successfully authenticated is
470 stored in the session as well as authentication token.
471
472 Default: timedelta(hours=24)
473
474 .. versionadded:: 3.4.0
475
476 .. py:data:: SECURITY_FRESHNESS_GRACE_PERIOD
477
478 A timedelta that provides a grace period when altering sensitive
479 information. This ensures that multi-step operations don't get denied
480 because the session/token happens to expire mid-step.
481
482 Note that this is not implemented for freshness information carried in the
483 auth token.
484
485 N.B. To avoid strange behavior, be sure to set the grace period less than
486 the freshness period.
487 Please see :meth:`flask_security.check_and_update_authn_fresh` for details.
488
489 Default: timedelta(hours=1)
490
491 .. versionadded:: 3.4.0
492
493 .. py:data:: SECURITY_FRESHNESS_ALLOW_AUTH_TOKEN
494
495 Controls whether the freshness data set in the auth token can be used to
496 satisfy freshness checks. Some applications might want to force freshness
497 protected endpoints to always use browser based access with sessions - they
498 should set this to ``False``.
499
500 Default: ``True``
501
502
503 .. versionadded:: 5.5.0
504
505 Core - Passwords and Tokens
506 ----------------------------
507 .. py:data:: SECURITY_PASSWORD_HASH
508
509 Specifies the password hash algorithm to use when hashing passwords.
510 Recommended values for production systems are ``argon2``, ``bcrypt``, or
511 ``pbkdf2_sha512``. Some algorithms require the installation of a backend package (e.g. `bcrypt`_, `argon2`_).
512
513 Default: ``"argon2"``.
514
515 .. versionchanged:: 5.5.0
516 Default changed from ``bcrypt`` to ``argon2``.
517
518 .. py:data:: SECURITY_PASSWORD_SCHEMES
519
520 List of supported password hash algorithms. ``SECURITY_PASSWORD_HASH``
521 must be from this list. Passwords encrypted with any of these schemes will be honored.
522 This is passed directly to `passlib's CryptoContext`_.
523
524 .. py:data:: SECURITY_DEPRECATED_PASSWORD_SCHEMES
525
526 List of password hash algorithms that are considered weak and
527 will be accepted, however on first use, will be re-hashed to the current
528 setting of ``SECURITY_PASSWORD_HASH``.
529 This is passed directly to `passlib's CryptoContext`_.
530
531 Default: ``["auto"]`` which means any password found that wasn't
532 hashed using ``SECURITY_PASSWORD_HASH`` will be re-hashed.
533
534 .. py:data:: SECURITY_PASSWORD_SALT
535
536 Specifies the HMAC salt. This is required for all schemes that
537 are configured for double hashing. A good salt can be generated using:
538 ``secrets.SystemRandom().getrandbits(128)``.
539
540 Default: ``None``.
541
542 .. py:data:: SECURITY_PASSWORD_SINGLE_HASH
543
544 A list of schemes that should not be hashed twice. By default, passwords are
545 hashed twice, first with :py:data:`SECURITY_PASSWORD_SALT`, and then with a random salt.
546
547 Default: a list of known schemes not working with double hashing (`django_{digest}`, `plaintext`).
548
549 .. py:data:: SECURITY_HASHING_SCHEMES
550
551 List of algorithms used for encrypting/hashing sensitive data within a token
552 (Such as is sent with confirmation or reset password).
553 This is passed directly to `passlib's CryptoContext`_.
554
555 Default: ``["sha256_crypt", "hex_md5"]``.
556 .. py:data:: SECURITY_DEPRECATED_HASHING_SCHEMES
557
558 List of deprecated algorithms used for creating and validating tokens.
559 This is passed directly to `passlib's CryptoContext`_.
560
561 Default: ``["auto"]``.
562
563 .. versionchanged:: 5.5.0
564 Default changed from ``hex_md5`` to ``auto``.
565
566 .. py:data:: SECURITY_PASSWORD_HASH_OPTIONS
567
568 Specifies additional options to be passed to the hashing method. This is deprecated as of passlib 1.7.
569
570 .. deprecated:: 3.4.0 see: :py:data:`SECURITY_PASSWORD_HASH_PASSLIB_OPTIONS`
571
572 .. py:data:: SECURITY_PASSWORD_HASH_PASSLIB_OPTIONS
573
574 Pass additional options through ``passlib`` to the various hashing methods.
575 This is a dict of the form ``{<scheme>__<option>: <value>, ..}``
576 e.g. {"argon2__time_cost": 3}.
577
578 Default: ``{}``
579
580 .. versionadded:: 3.3.1
581
582 .. py:data:: SECURITY_PASSWORD_LENGTH_MIN
583
584 Minimum required length for passwords.
585
586 Default: ``8``
587
588 .. versionadded:: 3.4.0
589 .. py:data:: SECURITY_PASSWORD_COMPLEXITY_CHECKER
590
591 Set to complexity checker to use (Only ``zxcvbn`` supported).
592
593 Default: ``None``
594
595 .. versionadded:: 3.4.0
596 .. py:data:: SECURITY_ZXCVBN_MINIMUM_SCORE
597
598 Required ``zxcvbn`` password complexity score (0-4).
599 Refer to https://github.com/dropbox/zxcvbn#usage for exact meanings of
600 different score values.
601
602 Default: ``3`` (Good or Strong)
603
604 .. versionadded:: 5.0.0
605 .. py:data:: SECURITY_PASSWORD_CHECK_BREACHED
606
607 If not ``None`` new/changed passwords will be checked against the
608 database of breached passwords at https://api.pwnedpasswords.com.
609 If set to ``strict`` then if the site can't be reached, validation will fail.
610 If set to ``best-effort`` failure to reach the site will continue
611 with the rest of password validation.
612
613 Default: ``None``
614
615 .. versionadded:: 3.4.0
616 .. py:data:: SECURITY_PASSWORD_BREACHED_COUNT
617
618 Passwords with counts greater than or equal to this value are considered breached.
619
620 Default: 1 - which might be to burdensome for some applications.
621
622 .. versionadded:: 3.4.0
623
624 .. py:data:: SECURITY_PASSWORD_NORMALIZE_FORM
625
626 Passwords are normalized prior to changing or comparing. This satisfies
627 the NIST requirement: `5.1.1.2 Memorized Secret Verifiers`_.
628 Normalization is performed using the Python unicodedata.normalize() method.
629
630 Default: ``"NFKD"``
631
632 .. versionadded:: 4.0.0
633
634 .. _5.1.1.2 Memorized Secret Verifiers: https://pages.nist.gov/800-63-3/sp800-63b.html#sec5
635
636 .. py:data:: SECURITY_PASSWORD_REQUIRED
637
638 If set to ``False`` then a user can register with an empty password.
639 This requires :py:data:`SECURITY_UNIFIED_SIGNIN` to be enabled. By
640 default, the user will be able to authenticate using an email link.
641 Please note: this does not mean a user can sign in with an empty
642 password - it means that they must have some OTHER means of authenticating.
643
644 Default: ``True``
645
646 .. versionadded:: 5.0.0
647
648 .. py:data:: SECURITY_PASSWORD_CONFIRM_REQUIRED
649
650 If set to ``True`` then during registration a 'password confirmation' field is presented.
651 N.B. this just applies to the new(er) RegisterFormV2 (see :py:data:`SECURITY_USE_REGISTER_V2`)
652
653 Default: ``True``
654
655 .. versionadded:: 5.6.0
656
657 Core - Multi-factor
658 -------------------
659 These are used by the Two-Factor and Unified Signin features.
660
661 .. py:data:: SECURITY_TOTP_SECRETS
662
663 Secret used to encrypt the totp_password both into DB and into the session cookie.
664 Best practice is to set this to:
665
666 .. code-block:: python
667
668 from passlib import totp
669 "{1: <result of totp.generate_secret()>}"
670
671 See: `Totp`_ for details.
672
673 .. versionadded:: 3.4.0
674
675 .. py:data:: SECURITY_TOTP_ISSUER
676
677 Specifies the name of the service or application that the user is authenticating to.
678 This will be the name displayed by most authenticator apps.
679
680 Default: ``None``.
681
682 .. versionadded:: 3.4.0
683
684 .. py:data:: SECURITY_SMS_SERVICE
685
686 Specifies the name of the sms service provider. Out of the box
687 "Twilio" is supported. For other sms service providers you will need
688 to subclass :class:`.SmsSenderBaseClass` and register it:
689
690 .. code-block:: python
691
692 SmsSenderFactory.senders[<service-name>] = <service-class>
693
694 Default: ``Dummy`` which does nothing.
695
696 .. versionadded:: 3.4.0
697
698 .. py:data:: SECURITY_SMS_SERVICE_CONFIG
699
700 Specifies a dictionary of basic configurations needed for use of a sms service.
701 For "Twilio" the following keys are required (fill in from your Twilio dashboard):
702
703 Default: ``{'ACCOUNT_SID': NONE, 'AUTH_TOKEN': NONE, 'PHONE_NUMBER': NONE}``
704
705 .. versionadded:: 3.4.0
706
707 .. py:data:: SECURITY_PHONE_REGION_DEFAULT
708
709 Assigns a default 'region' for phone numbers used for two-factor or
710 unified sign in. All other phone numbers will require a region prefix to
711 be accepted.
712
713 Default: ``"US"``
714
715 .. versionadded:: 3.4.0
716
717 Core - Compatibility
718 ---------------------
719 These are flags that change various backwards compatability functionality.
720
721 .. py:data:: SECURITY_ANONYMOUS_USER_DISABLED
722
723 If set to `True` then :data:`flask_security.current_user` will be `None` for unauthenticated
724 users instead of pointing to an AnonymousUser object. Note that Flask-Login intends
725 to deprecate the entire AnonymousUser concept.
726
727 Default: ``False``.
728
729 .. versionadded:: 5.4.0
730
731 .. py:data:: SECURITY_BACKWARDS_COMPAT_AUTH_TOKEN
732
733 If set to ``True`` then an Authentication-Token will be returned
734 on every successful call to login, reset-password, change-password
735 as part of the JSON response. This was the default prior to release 3.3.0
736 - however sending Authentication-Tokens (which by default don't expire)
737 to session based UIs is a bad security practice.
738
739 Default: ``False``.
740
741 Core - rarely need changing
742 ----------------------------
743
744 .. py:data:: SECURITY_DATETIME_FACTORY
745
746 Specifies the default datetime factory. The default is naive-UTC which
747 corresponds to many DB's DateTime type.
748
749 Default:``flask_security.naive_utcnow``.
750
751 .. py:data:: SECURITY_CONFIRM_SALT
752
753 Specifies the salt value when generating confirmation links/tokens.
754
755 Default: ``"confirm-salt"``.
756
757 .. py:data:: SECURITY_RESET_SALT
758
759 Specifies the salt value when generating password reset links/tokens.
760
761 Default: ``"reset-salt"``.
762
763 .. py:data:: SECURITY_LOGIN_SALT
764
765 Specifies the salt value when generating login links/tokens.
766
767 Default: ``"login-salt"``.
768
769 .. py:data:: SECURITY_REMEMBER_SALT
770
771 Specifies the salt value when generating remember tokens.
772 Remember tokens are used instead of user ID's as it is more secure.
773
774 Default: ``"remember-salt"``.
775 .. py:data:: SECURITY_TWO_FACTOR_VALIDITY_SALT
776
777 Specifies the salt value when generating two-factor validity tokens.
778
779 Default: ``"tf-validity-salt"``.
780 .. py:data:: SECURITY_US_SETUP_SALT
781
782 Default: ``"us-setup-salt"``
783
784 .. py:data:: SECURITY_WAN_SALT
785
786 Default: ``"wan-salt"``
787
788 .. py:data:: SECURITY_REFRESH_TOKEN_SALT
789
790 Default: ``"refresh-token-salt"``
791 .. py:data:: SECURITY_TWO_FACTOR_SETUP_SALT
792
793 Default: ``"tf-setup-salt"``
794 .. py:data:: SECURITY_EMAIL_CHANGE_SALT
795
796 Specifies the salt value when generating change email confirmation links/tokens.
797
798 Default: ``"change-email-salt"``.
799
800 .. py:data:: SECURITY_EMAIL_PLAINTEXT
801
802 Sends email as plaintext using ``*.txt`` template.
803
804 Default: ``True``.
805
806 .. py:data:: SECURITY_EMAIL_HTML
807
808 Sends email as HTML using ``*.html`` template.
809
810 Default: ``True``.
811
812 .. py:data:: SECURITY_CLI_USERS_NAME
813
814 Specifies the name for the command managing users. Disable by setting ``False``.
815
816 Default: ``"users"``.
817
818 .. py:data:: SECURITY_CLI_ROLES_NAME
819
820 Specifies the name for the command managing roles. Disable by setting ``False``.
821
822 Default: ``"roles"``.
823
824 .. py:data:: SECURITY_JOIN_USER_ROLES
825
826 Specifies whether to set the ``UserModel.roles`` loading relationship to ``joined`` when a ``roles`` attribute
827 is present for a SQLAlchemy Datastore. Setting this to ``False`` restores pre 3.3.0 behavior and is required if the ``roles`` attribute
828 is not a joinable attribute on the ``UserModel``. The default setting improves performance by only requiring a single
829 DB call.
830
831 Default: ``True``.
832
833 .. versionadded:: 3.4.0
834
835 .. _Totp: https://passlib.readthedocs.io/en/stable/narr/totp-tutorial.html#totp-encryption-setup
836 .. _set_cookie: https://flask.palletsprojects.com/en/1.1.x/api/?highlight=set_cookie#flask.Response.set_cookie
837 .. _axios: https://github.com/axios/axios
838 .. _bcrypt: https://pypi.org/project/bcrypt/
839 .. _argon2: https://pypi.org/project/argon2-cffi/
840
841 Login/Logout
842 ------------
843 .. py:data:: SECURITY_LOGIN_URL
844
845 Specifies the login URL.
846
847 Default: ``"/login"``.
848
849 .. py:data:: SECURITY_LOGOUT_URL
850
851 Specifies the logout URL.
852
853 Default:``"/logout"``.
854
855
856 .. py:data:: SECURITY_LOGOUT_METHODS
857
858 Specifies the HTTP request methods that the logout URL accepts. Specify ``None`` to disable the logout URL (and implement your own).
859 Configuring with just ``["POST"]`` is slightly more secure in that it avoids a class of attacks that can force a user to be logged out
860 just by clicking on a link.
861
862 Default: ``["POST"]``.
863
864 .. versionchanged:: 5.9.0
865 Default changed to just allowing ``"POST"``.
866
867
868 .. py:data:: SECURITY_POST_LOGIN_VIEW
869
870 Specifies the default view to redirect to after a user logs in. This value can be set to a URL
871 or an endpoint name. Defaults to the Flask config ``APPLICATION_ROOT`` value which itself defaults to ``"/"``.
872 Note that if the request URL or form has a ``next`` parameter, that will take precedence.
873
874 Default: ``APPLICATION_ROOT``.
875
876 .. py:data:: SECURITY_POST_LOGOUT_VIEW
877
878 Specifies the default view to redirect to after a user logs out. This value can be set to a URL
879 or an endpoint name. Defaults to the Flask config ``APPLICATION_ROOT`` value which itself defaults to ``"/"``.
880 Note that if the request URL or form has a ``next`` parameter, that will take precedence.
881
882 Default: ``APPLICATION_ROOT``.
883
884
885 .. py:data:: SECURITY_UNAUTHORIZED_VIEW
886
887 Specifies the view to redirect to if a user attempts to access a URL/endpoint that they do
888 not have permission to access. This can be a callable (which returns a URL or ``None``) or an endpoint or a URL.
889 If this value is ``None`` or the configured callable returns ``None`` or empty, the user is presented with a default HTTP 403 response.
890
891 Default: ``None``.
892
893 .. py:data:: SECURITY_LOGIN_USER_TEMPLATE
894
895 Specifies the path to the template for the user login page.
896
897 Default: ``"security/login_user.html"``.
898
899 .. py:data:: SECURITY_LOGOUT_USER_TEMPLATE
900
901 Specifies the path to the template for the logout page.
902 Note this is only returned on POST error.
903
904 Default: ``"security/logout_user.html"``.
905
906 .. versionadded:: 5.9.0
907
908 .. py:data:: SECURITY_LOGOUT_CSRF
909
910 Should the logout view enforce CSRF. If set to ``"True"`` and if there is a
911 CSRF token mismatch then the ``"SECURITY_LOGOUT_USER_TEMPLATE"`` will be
912 returned (if request was a form post). For a JSON request, a 400 response will
913 be returned.
914
915 Default: ``False``
916
917 .. danger::
918 Be sure to not configure ``"GET"`` as an accepted method since that is not
919 CSRF protected.
920
921 .. versionadded:: 5.9.0
922
923 .. py:data:: SECURITY_VERIFY_URL
924
925 Specifies the reauthenticate URL. If :py:data:`SECURITY_FRESHNESS` evaluates to < 0; this
926 endpoint won't be registered.
927
928 Default: ``"/verify"``
929
930 .. versionadded:: 3.4.0
931
932
933 .. py:data:: SECURITY_VERIFY_TEMPLATE
934
935 Specifies the path to the template for the verify password page.
936
937 Default: ``"security/verify.html"``.
938
939 .. versionadded:: 3.4.0
940
941 .. py:data:: SECURITY_POST_VERIFY_URL
942
943 Specifies the default view to redirect to after a user successfully reauthenticates either via
944 the :py:data:`SECURITY_VERIFY_URL` or the :py:data:`SECURITY_US_VERIFY_URL`.
945 Normally this won't need to be set and after the verification/reauthentication, the referring
946 view (held in the ``next`` parameter) will be redirected to.
947
948 Default: ``None``.
949
950 .. versionadded:: 3.4.0
951
952 Registerable
953 ------------
954 .. py:data:: SECURITY_REGISTERABLE
955
956 Specifies if Flask-Security should create a user registration endpoint.
957
958 Default: ``False``
959
960 .. py:data:: SECURITY_SEND_REGISTER_EMAIL
961
962 Specifies whether registration email is sent.
963
964 Default: ``True``.
965 .. py:data:: SECURITY_EMAIL_SUBJECT_REGISTER
966
967 Sets the subject for the confirmation email.
968
969 Default: ``_("Welcome")``.
970 .. py:data:: SECURITY_REGISTER_USER_TEMPLATE
971
972 Specifies the path to the template for the user registration page.
973
974 Default: ``"security/register_user.html"``.
975 .. py:data:: SECURITY_POST_REGISTER_VIEW
976
977 Specifies the view to redirect to after a user successfully registers.
978 This value can be set to a URL or an endpoint name. If this value is
979 ``None``, the user is redirected to the value of :data:`SECURITY_POST_LOGIN_VIEW`.
980 Note that if the request URL or form has a ``next`` parameter, that will take precedence.
981
982 Default: ``None``.
983 .. py:data:: SECURITY_REGISTER_URL
984
985 Specifies the register URL.
986
987 Default: ``"/register"``.
988
989 .. py:data:: SECURITY_USERNAME_ENABLE
990
991 If set to True, the default registration form and template, and
992 login form and template will have
993 a username field added. This requires that your user model contain the
994 field ``username``. It MUST be set as 'unique' and if you don't want
995 to require a username, it should be set as 'nullable'.
996 The form validators will call :meth:`.UsernameUtil.validate`.
997
998 In addition, :data:`SECURITY_USER_IDENTITY_ATTRIBUTES` will be updated to include::
999
1000 {"username": {"mapper": uia_username_mapper}, "case_insensitive": True}
1001
1002 See :meth:`flask_security.uia_username_mapper` for details.
1003
1004 If you already have added a username field to your forms, don't set this
1005 option - the system will throw an exception at init_app time.
1006
1007 Validation and normalization is encapsulated in :class:`.UsernameUtil`.
1008 Note that the default validation restricts username input to be unicode
1009 letters and numbers. It also uses ``nh3`` to scrub any risky input. Be
1010 sure your application requirements includes `nh3`_.
1011
1012 Default: ``False``
1013
1014 .. versionadded:: 4.1.0
1015 .. py:data:: SECURITY_REGISTER_EMAIL_TEMPLATE
1016
1017 Specifies the path to the template for the email sent when
1018 a new account has been registered.
1019
1020 Default: ``"security/email/welcome"``
1021
1022 .. versionadded:: 5.9.0
1023 .. py:data:: SECURITY_REGISTER_EMAIL_EXISTING_USERNAME_TEMPLATE
1024
1025 Specifies the path to the template for the email sent when
1026 attempting to register a new account but the selected username
1027 is already in use by another account.
1028 This is only sent if :py:data:`SECURITY_RETURN_GENERIC_RESPONSES` is set.
1029 Please see :ref:`generic_responses`.
1030
1031 Default: ``"security/email/welcome_existing_username"``
1032
1033 .. versionadded:: 5.9.0
1034 .. py:data:: SECURITY_REGISTER_EMAIL_EXISTING_TEMPLATE
1035
1036 Specifies the path to the template for the email sent when
1037 attempting to register a new account but the selected email
1038 ss already in the system.
1039 This is only sent if :py:data:`SECURITY_RETURN_GENERIC_RESPONSES` is set.
1040 Please see :ref:`generic_responses`.
1041
1042 Default: ``"security/email/welcome_existing"``
1043
1044 .. versionadded:: 5.9.0
1045
1046 .. py:data:: SECURITY_USERNAME_REQUIRED
1047
1048 If username is enabled, is it required as part of registration?
1049
1050 Default: ``False``
1051
1052 .. versionadded:: 4.1.0
1053
1054 .. py:data:: SECURITY_USERNAME_ALLOWED_CHARS
1055
1056 Define which unicode categories are used to validate usernames.
1057
1058 Default: ``["L", "N"]``
1059
1060 .. versionadded:: 5.9.0
1061
1062 .. py:data:: SECURITY_USERNAME_MIN_LENGTH
1063
1064 Minimum length of a username.
1065
1066 Default: ``4``
1067
1068 .. versionadded:: 4.1.0
1069
1070 .. py:data:: SECURITY_USERNAME_MAX_LENGTH
1071
1072 Maximum length of a username.
1073
1074 Default: ``32``
1075
1076 .. versionadded:: 4.1.0
1077
1078 .. py:data:: SECURITY_USE_REGISTER_V2
1079
1080 The :py:class:`flask_security.RegisterFormV2` is a single form used for registration. This is replacing the
1081 RegisterForm and ConfirmRegisterForm (over a few releases). Setting this option
1082 to ``False`` will revert behavior to prior releases with register_form=RegisterForm and
1083 confirm_register_form=ConfirmRegisterForm. Note that this
1084 option is ignored if the application has sub-classed the registration form.
1085
1086 Default: ``True``
1087
1088 .. versionadded:: 5.6.0
1089 .. versionchanged:: 5.7.0
1090 Default set to ``True``
1091 .. deprecated:: 5.7.0
1092 In a future release the old RegisterForm and ConfirmRegisterForm will be removed which
1093 will make this option obsolete.
1094
1095
1096
1097 Confirmable
1098 -----------
1099
1100 .. py:data:: SECURITY_CONFIRMABLE
1101
1102 Specifies if users are required to confirm their email address when
1103 registering a new account. If this value is `True`, Flask-Security creates an endpoint to handle
1104 confirmations and requests to resend confirmation instructions.
1105
1106 Default: ``False``.
1107 .. py:data:: SECURITY_CONFIRM_EMAIL_WITHIN
1108
1109 Specifies how long until the confirmation link expires.
1110
1111 Default: ``timedelta(days=2)``.
1112
1113 .. versionchanged:: 5.9.0
1114 Accepted value changed to a timedelta
1115 .. py:data:: SECURITY_CONFIRM_URL
1116
1117 Specifies the email confirmation URL.
1118
1119 Default: ``"/confirm"``.
1120 .. py:data:: SECURITY_SEND_CONFIRMATION_TEMPLATE
1121
1122 Specifies the path to the template for the resend confirmation instructions page.
1123
1124 Default: ``"security/send_confirmation.html"``.
1125 .. py:data:: SECURITY_EMAIL_SUBJECT_CONFIRM
1126
1127 Sets the subject for the email confirmation message.
1128
1129 Default: ``_("Please confirm your email")``.
1130 .. py:data:: SECURITY_EMAIL_TEMPLATE_CONFIRM
1131
1132 Specifies the path to the template for the email send confirmation instructions.
1133
1134 Default: ``"security/email/confirmation_instructions"``
1135
1136 .. versionadded:: 5.9.0
1137 .. py:data:: SECURITY_CONFIRM_ERROR_VIEW
1138
1139 Specifies the view to redirect to if a confirmation error occurs.
1140 This value can be set to a URL or an endpoint name.
1141 If this value is ``None``, the user is presented the default view
1142 to resend a confirmation link. In the case of :py:data:`SECURITY_REDIRECT_BEHAVIOR` == ``"spa"``
1143 query params in the redirect will contain the error.
1144
1145 Default: ``None``.
1146 .. py:data:: SECURITY_POST_CONFIRM_VIEW
1147
1148 Specifies the view to redirect to after a user successfully confirms their email.
1149 This value can be set to a URL or an endpoint name. If this value is ``None``, the user is redirected to the
1150 value of :data:`SECURITY_POST_LOGIN_VIEW`.
1151
1152 Default: ``None``.
1153 .. py:data:: SECURITY_AUTO_LOGIN_AFTER_CONFIRM
1154
1155 If ``True``, then the user corresponding to the confirmation token will be automatically signed in.
1156 If ``False`` (the default) then the user will be required to authenticate using the usual mechanism(s).
1157 Note that the confirmation token is single-use. This is not recommended by OWASP
1158 however an application that is by invite only (no self-registration) might find this useful.
1159
1160 Default: ``False``.
1161
1162 .. py:data:: SECURITY_LOGIN_WITHOUT_CONFIRMATION
1163
1164 Specifies if a user may login before confirming their email when
1165 the value of :data:`SECURITY_CONFIRMABLE` is set to ``True``.
1166
1167 Default: ``False``.
1168 .. py:data:: SECURITY_REQUIRES_CONFIRMATION_ERROR_VIEW
1169
1170 Specifies a redirect page if the users tries to login, reset password or us-signin with an unconfirmed account.
1171 If an URL endpoint is specified, flashes an error messages and redirects.
1172 Default behavior is to reload the form with an error message without redirecting to an other page.
1173
1174 Default: ``None``.
1175
1176 Changeable
1177 ----------
1178
1179 .. py:data:: SECURITY_CHANGEABLE
1180
1181 Specifies if Flask-Security should enable the change password endpoint.
1182
1183 Default: ``False``.
1184 .. py:data:: SECURITY_CHANGE_URL
1185
1186 Specifies the password change URL.
1187
1188 Default: ``"/change"``.
1189 .. py:data:: SECURITY_POST_CHANGE_VIEW
1190
1191 Specifies the view to redirect to after a user successfully changes their password.
1192 This value can be set to a URL or an endpoint name.
1193 If this value is ``None``, the user is redirected to the
1194 value of :data:`SECURITY_POST_LOGIN_VIEW`.
1195
1196 Default: ``None``.
1197 .. py:data:: SECURITY_CHANGE_PASSWORD_TEMPLATE
1198
1199 Specifies the path to the template for the change password page.
1200
1201 Default: ``"security/change_password.html"``.
1202
1203 .. py:data:: SECURITY_SEND_PASSWORD_CHANGE_EMAIL
1204
1205 Specifies whether password change email is sent.
1206
1207 Default: ``True``.
1208
1209 .. py:data:: SECURITY_EMAIL_SUBJECT_PASSWORD_CHANGE_NOTICE
1210
1211 Sets the subject for the password change notice.
1212
1213 Default: ``_("Your password has been changed")``.
1214 .. py:data:: SECURITY_EMAIL_TEMPLATE_PASSWORD_CHANGE_NOTICE
1215
1216 Specifies the path to the template for the email sent on successful
1217 password change.
1218
1219 Default: ``"security/email/change_notice"``
1220
1221 .. versionadded:: 5.9.0
1222
1223 Recoverable
1224 -----------
1225
1226 .. py:data:: SECURITY_RECOVERABLE
1227
1228 Specifies if Flask-Security should create a password reset/recover endpoint.
1229
1230 Default: ``False``.
1231
1232 .. py:data:: SECURITY_RESET_URL
1233
1234 Specifies the password reset URL.
1235
1236 Default: ``"/reset"``.
1237
1238 .. py:data:: SECURITY_RESET_PASSWORD_TEMPLATE
1239
1240 Specifies the path to the template for the reset password page.
1241
1242 Default: ``"security/reset_password.html"``.
1243
1244 .. py:data:: SECURITY_FORGOT_PASSWORD_TEMPLATE
1245
1246 Specifies the path to the template for the forgot password page.
1247
1248 Default: ``"security/forgot_password.html"``.
1249
1250 .. py:data:: SECURITY_POST_RESET_VIEW
1251
1252 Specifies the view to redirect to after a user successfully resets their password.
1253 This value can be set to a URL or an endpoint name. If this
1254 value is ``None``, the user is redirected to the value of ``.login`` if
1255 :py:data:`SECURITY_AUTO_LOGIN_AFTER_RESET` is ``False`` or :py:data:`SECURITY_POST_LOGIN_VIEW`
1256 if ``True``
1257
1258 Default: ``None``.
1259
1260 .. py:data:: SECURITY_RESET_VIEW
1261
1262 Specifies the view/URL to redirect to after a GET reset-password link.
1263 This is only valid if :py:data:`SECURITY_REDIRECT_BEHAVIOR` == ``"spa"``.
1264 Query params in the redirect will contain the ``token``.
1265
1266 Default: ``None``.
1267
1268 .. py:data:: SECURITY_AUTO_LOGIN_AFTER_RESET
1269
1270 If ``False`` then on successful reset the user will be required to signin again.
1271 Note that the reset token is not valid after being used once.
1272 If ``True``, then the user corresponding to the
1273 reset token will be automatically signed in. Note: auto-login is contrary
1274 to OWASP best security practices. This option is for backwards compatibility
1275 and is deprecated.
1276
1277 Default: ``False``.
1278
1279 .. versionadded:: 5.3.0
1280 .. deprecated:: 5.3.0
1281
1282 .. py:data:: SECURITY_RESET_ERROR_VIEW
1283
1284 Specifies the view/URL to redirect to after a GET reset-password link when there is an error.
1285 This is only valid if :py:data:`SECURITY_REDIRECT_BEHAVIOR` == ``spa``.
1286 Query params in the redirect will contain the error.
1287
1288 Default: ``None``.
1289
1290 .. py:data:: SECURITY_RESET_PASSWORD_WITHIN
1291
1292 Specifies how long until the reset link expires.
1293
1294 Default: ``timedelta(days=1)``.
1295
1296 .. versionchanged:: 5.9.0
1297 Accepted value changed to a timedelta
1298
1299 .. py:data:: SECURITY_SEND_PASSWORD_RESET_EMAIL
1300
1301 Specifies whether password reset email is sent. These are instructions
1302 including a link that can be clicked on.
1303
1304 Default: ``True``.
1305
1306 .. py:data:: SECURITY_SEND_PASSWORD_RESET_NOTICE_EMAIL
1307
1308 Specifies whether password reset notice email is sent. This is sent once
1309 a user's password was successfully reset.
1310
1311 Default: ``True``.
1312
1313 .. py:data:: SECURITY_EMAIL_SUBJECT_PASSWORD_RESET
1314
1315 Sets the subject for the password reset email.
1316
1317 Default: ``_("Password reset instructions")``.
1318
1319 .. py:data:: SECURITY_EMAIL_TEMPLATE_PASSWORD_RESET
1320
1321 Specifies the path to the template for the email sent with password reset instructions.
1322
1323 Default: ``"security/email/reset_instructions"``
1324
1325 .. versionadded:: 5.9.0
1326
1327 .. py:data:: SECURITY_EMAIL_SUBJECT_PASSWORD_NOTICE
1328
1329 Sets subject for the password notice.
1330
1331 Default: ``_("Your password has been reset")``.
1332 .. py:data:: SECURITY_EMAIL_TEMPLATE_PASSWORD_RESET_NOTICE
1333
1334 Specifies the path to the template for the email sent on successful password reset.
1335
1336 Default: ``"security/email/reset_notice"``
1337
1338 .. versionadded:: 5.9.0
1339
1340
1341 Change-Email
1342 ------------
1343 .. versionadded:: 5.5.0
1344
1345 .. py:data:: SECURITY_CHANGE_EMAIL
1346
1347 It ``True`` an endpoint is created that allows a user to change their email address.
1348
1349 Default: ``False``
1350 .. py:data:: SECURITY_CHANGE_EMAIL_SUBJECT
1351
1352 Sets the subject for the change email confirmation email.
1353
1354 Default: ``_("Confirm your new email address")``.
1355 .. py:data:: SECURITY_CHANGE_EMAIL_EMAIL_TEMPLATE
1356
1357 Specifies the path to the template for the change email email instructions.
1358
1359 Default: ``"security/email/change_email_instructions"``
1360
1361 .. versionadded:: 5.9.0
1362 .. py:data:: SECURITY_CHANGE_EMAIL_TEMPLATE
1363
1364 Specifies the path to the template for the change email page.
1365
1366 Default: ``"security/change_email.html"``.
1367 .. py:data:: SECURITY_CHANGE_EMAIL_WITHIN
1368
1369 Specifies how long until the change email token expires.
1370
1371 Default: ``timedelta(hours=2)``.
1372
1373 .. versionchanged:: 5.9.0
1374 Accepted value changed to a timedelta
1375 .. py:data:: SECURITY_POST_CHANGE_EMAIL_VIEW
1376
1377 Specifies the view to redirect to after a user successfully confirms their new email address.
1378 This value can be set to a URL or an endpoint name. If this value is
1379 ``None``, the user is redirected to the value of :py:data:`SECURITY_POST_LOGIN_VIEW`.
1380 Note that if the request URL or form has a ``next`` parameter, that will take precedence.
1381 In the case of :py:data:`SECURITY_REDIRECT_BEHAVIOR` == ``"spa"`` this value must be set.
1382
1383 Default: ``None``.
1384 .. py:data:: SECURITY_CHANGE_EMAIL_ERROR_VIEW
1385
1386 Specifies the view to redirect to if a change email confirmation error occurs.
1387 This value can be set to a URL or an endpoint name.
1388 If this value is ``None``, the user is redirected back to the change_email page.
1389 In the case of :py:data:`SECURITY_REDIRECT_BEHAVIOR` == ``"spa"``
1390 this value must be set, and the query params in the redirect will contain the error.
1391
1392 Default: ``None``.
1393 .. py:data:: SECURITY_CHANGE_EMAIL_URL
1394
1395 Specifies the change-email endpoint URL.
1396
1397 Default: ``"/change-email"``.
1398 .. py:data:: SECURITY_CHANGE_EMAIL_CONFIRM_URL
1399
1400 Specifies the change-email confirmation endpoint URL. This is a GET
1401 only endpoint (accessed via a link in an email).
1402
1403 Default: ``"/change-email-confirm"``.
1404
1405 Additional relevant configuration variables:
1406
1407 - :py:data:`SECURITY_FRESHNESS` - Used to protect /change-email.
1408 - :py:data:`SECURITY_FRESHNESS_GRACE_PERIOD` - Used to protect /change-email.
1409
1410 Two-Factor
1411 -----------
1412 Configuration related to the two-factor authentication feature.
1413
1414 .. versionadded:: 3.2.0
1415
1416 .. py:data:: SECURITY_TWO_FACTOR
1417
1418 Specifies if Flask-Security should enable the two-factor login feature.
1419
1420 Default: ``False``
1421 .. py:data:: SECURITY_TWO_FACTOR_REQUIRED
1422
1423 If set to ``True`` then all users will be required to setup and use two-factor authentication.
1424 Please see :py:meth:`.UserMixin.check_tf_required` and :ref:`two_factor_configurations:Fine-Grained Control of Two-Factor`
1425 for ways the application can
1426 more finely tune which users require two-factor authentication.
1427
1428 Default: ``False``
1429
1430 .. versionchanged:: 5.8.0
1431 Added overridable method that can alter this behavior.
1432
1433 .. py:data:: SECURITY_TWO_FACTOR_ENABLED_METHODS
1434
1435 Specifies the default enabled methods for two-factor authentication.
1436
1437 Default: ``['email', 'authenticator', 'sms']`` which are the only currently supported methods.
1438 .. py:data:: SECURITY_TWO_FACTOR_AUTHENTICATOR_VALIDITY
1439
1440 Specifies the number of seconds access token is valid.
1441
1442 Default: ``120``
1443 .. py:data:: SECURITY_TWO_FACTOR_MAIL_VALIDITY
1444
1445 Specifies the number of seconds access token is valid.
1446
1447 Default: ``300``
1448 .. py:data:: SECURITY_TWO_FACTOR_SMS_VALIDITY
1449
1450 Specifies the number of seconds access token is valid.
1451
1452 Default: ``120``
1453 .. py:data:: SECURITY_TWO_FACTOR_SETUP_WITHIN
1454
1455 Specifies how long until the setup token expires.
1456
1457 Default: ``timedelta(minutes=30)``
1458
1459 .. versionchanged:: 5.9.0
1460 Accepted value changed to a timedelta
1461
1462 .. versionadded:: 5.5.0
1463 .. py:data:: SECURITY_TWO_FACTOR_RESCUE_MAIL
1464
1465 Specifies the email address users send mail to when they can't complete the
1466 two-factor authentication login.
1467
1468 Default: ``"no-reply@localhost"``
1469
1470 .. py:data:: SECURITY_EMAIL_SUBJECT_TWO_FACTOR
1471
1472 Sets the subject for the two-factor feature.
1473
1474 Default: ``_("Two-Factor Login")``
1475 .. py:data:: SECURITY_EMAIL_SUBJECT_TWO_FACTOR_RESCUE
1476
1477 Sets the subject for the two-factor help function.
1478
1479 Default: ``_("Two-Factor Rescue")``
1480 .. py:data:: SECURITY_TWO_FACTOR_VERIFY_CODE_TEMPLATE
1481
1482 Specifies the path to the template for the verify code page for the two-factor authentication process.
1483
1484 Default: ``"security/two_factor_verify_code.html"``
1485 .. py:data:: SECURITY_TWO_FACTOR_SETUP_TEMPLATE
1486
1487 Specifies the path to the template for the setup page for the two-factor authentication process.
1488
1489 Default: ``"security/two_factor_setup.html"``
1490
1491 .. py:data:: SECURITY_TWO_FACTOR_SETUP_URL
1492
1493 Specifies the two-factor setup URL.
1494
1495 Default: ``"/tf-setup"``
1496 .. py:data:: SECURITY_TWO_FACTOR_TOKEN_VALIDATION_URL
1497
1498 Specifies the two-factor token validation URL.
1499
1500 Default: ``"/tf-validate"``
1501 .. py:data:: SECURITY_TWO_FACTOR_RESCUE_URL
1502
1503 Specifies the two-factor rescue URL.
1504
1505 Default: ``"/tf-rescue"``
1506 .. py:data:: SECURITY_TWO_FACTOR_SELECT_URL
1507
1508 Specifies the two-factor select URL. This is used when the user has
1509 setup more than one second factor - see :ref:`webauthn:webauthn`.
1510
1511 Default: ``"/tf-select"``
1512
1513 .. versionadded:: 5.0.0
1514
1515 .. py:data:: SECURITY_TWO_FACTOR_EMAIL_TEMPLATE
1516
1517 Specifies the path to the template for the email providing the code for authentication.
1518
1519 Default: ``"security/email/two_factor_instructions"``
1520
1521 .. versionadded:: 5.9.0
1522 .. py:data:: SECURITY_TWO_FACTOR_ERROR_VIEW
1523
1524 Specifies a URL or endpoint to redirect to if the system detects that
1525 a two-factor endpoint is being accessed without the proper state. For example
1526 if ``tf-validate`` is accessed but the caller hasn't yet successfully passed the
1527 primary authentication.
1528
1529 Default: ``".login"``
1530
1531 .. versionadded:: 5.1.0
1532
1533 .. py:data:: SECURITY_TWO_FACTOR_POST_SETUP_VIEW
1534
1535 Specifies the view to redirect to after a user successfully setups a two-factor method (non-json).
1536 This value can be set to a URL or an endpoint name.
1537
1538 Default: ``".two_factor_setup"``
1539
1540 .. versionadded:: 5.1.0
1541
1542 .. py:data:: SECURITY_TWO_FACTOR_SELECT_TEMPLATE
1543
1544 Specifies the path to the template for the select method page for the two-factor authentication process.
1545 This is used when more than one two-factor method has been setup (e.g. SMS and Webauthn).
1546
1547 Default: ``"security/two_factor_select.html"``
1548
1549 .. versionadded:: 5.0.0
1550
1551 .. py:data:: SECURITY_TWO_FACTOR_ALWAYS_VALIDATE
1552
1553 Specifies whether the application should require a two-factor code upon every login.
1554 If set to ``False`` then the values below are used to determine when
1555 a code is required. Note that this is cookie based - so a new browser
1556 session will always require a fresh two-factor code.
1557
1558 Default: ``True``
1559 .. py:data:: SECURITY_TWO_FACTOR_LOGIN_VALIDITY
1560
1561 Specifies the expiration of the two-factor validity cookie and verification of the token.
1562
1563 Default: ``timedelta(days=30)``
1564
1565 .. versionchanged:: 5.9.0
1566 Accepted value changed to a timedelta
1567
1568
1569 .. py:data:: SECURITY_TWO_FACTOR_VALIDITY_COOKIE_NAME
1570
1571 Name for the two factor validity cookie.
1572
1573 Default: ``"tf_validity"``
1574
1575 .. versionadded:: 5.9.0
1576
1577 .. py:data:: SECURITY_TWO_FACTOR_VALIDITY_COOKIE
1578
1579 A dictionary containing the parameters of the two-factor validity cookie.
1580 The complete set of parameters is described in Flask's `set_cookie`_ documentation.
1581
1582 Default: ``{'httponly': True, 'secure': True, 'samesite': "Strict"}``
1583
1584
1585 .. versionchanged:: 5.9.0
1586 ``secure`` default changed to ``True``. ``samesite`` default changed to ``Strict``
1587
1588 .. py:data:: SECURITY_TWO_FACTOR_IMPLEMENTATIONS
1589
1590 A dictionary of supported second factor implementations. All of these must
1591 implement the TfPluginBase interface.
1592
1593 Default: ``{"code": "flask_security.twofactor.CodeTfPlugin", "webauthn": "flask_security.webauthn.WebAuthnTfPlugin",}``
1594
1595 .. versionadded:: 5.0.0
1596
1597 .. py:data:: SECURITY_TWO_FACTOR_RESCUE_EMAIL
1598
1599 If True, then the 'email' option for two-factor rescue is enabled - allowing a user to
1600 recover a missing/inoperable second factor device by requesting a one time code sent to their email.
1601 While this is very convenient is has the downside that if a user's email is hacked, their second factor
1602 is useless to protect their account.
1603
1604 Default: ``True``
1605
1606 .. versionadded:: 5.0.0
1607 .. py:data:: SECURITY_TWO_FACTOR_RESCUE_EMAIL_TEMPLATE
1608
1609 Specifies the path to the template for the email sent to admin account
1610 in the case a user can't access any two-factor method.
1611
1612 Default: ``"security/email/two_factor_rescue"``
1613
1614 .. versionadded:: 5.9.0
1615
1616 Unified Signin
1617 --------------
1618
1619 Unified sign in provides a generalized sign in endpoint that takes an `identity`
1620 and a `passcode`.
1621
1622 .. versionadded:: 3.4.0
1623
1624 .. py:data:: SECURITY_UNIFIED_SIGNIN
1625
1626 To enable this feature - set this to ``True``.
1627
1628 Default: ``False``
1629
1630 .. py:data:: SECURITY_US_SIGNIN_URL
1631
1632 Sign in a user with an identity and a passcode.
1633
1634 Default: ``"/us-signin"``
1635
1636 .. py:data:: SECURITY_US_SIGNIN_SEND_CODE_URL
1637
1638 Endpoint that given an identity, and a previously setup authentication method, will
1639 generate and return a one time code. This isn't necessary when using an authenticator
1640 app.
1641
1642 Default: ``"/us-signin/send-code"``
1643
1644 .. py:data:: SECURITY_US_SETUP_URL
1645
1646 Endpoint for setting up and validating SMS or an authenticator app for use in
1647 receiving one-time codes.
1648
1649 Default: ``"/us-setup"``
1650
1651 .. py:data:: SECURITY_US_VERIFY_LINK_URL
1652
1653 This endpoint handles the 'magic link' that is sent when the user requests a code
1654 via email. It is mostly just accessed via a ``GET`` from an email reader.
1655
1656 Default: ``"/us-verify-link"``
1657
1658 .. py:data:: SECURITY_US_VERIFY_URL
1659
1660 This endpoint handles reauthentication, the caller must be already authenticated
1661 and then enter in their primary credentials (password/passcode) again. This is
1662 used when an endpoint (such as ``/us-setup``) fails freshness checks.
1663 This endpoint won't be registered if :py:data:`SECURITY_FRESHNESS` evaluates to < 0.
1664
1665 Default: ``"/us-verify"``
1666
1667 .. py:data:: SECURITY_US_VERIFY_SEND_CODE_URL
1668
1669 As part of ``/us-verify``, this endpoint will send the appropriate code.
1670 This endpoint won't be registered if :py:data:`SECURITY_FRESHNESS` evaluates to < 0.
1671
1672 Default: ``"/us-verify/send-code"``
1673
1674 .. py:data:: SECURITY_US_POST_SETUP_VIEW
1675
1676 Specifies the view to redirect to after a user successfully setups an authentication method (non-json).
1677 This value can be set to a URL or an endpoint name.
1678
1679 Default: ``".us-setup"``
1680
1681 .. py:data:: SECURITY_US_SIGNIN_TEMPLATE
1682
1683 Default: ``"security/us_signin.html"``
1684
1685 .. py:data:: SECURITY_US_SETUP_TEMPLATE
1686
1687 Default: ``"security/us_setup.html"``
1688
1689 .. py:data:: SECURITY_US_VERIFY_TEMPLATE
1690
1691 Default: ``"security/us_verify.html"``
1692
1693 .. py:data:: SECURITY_US_EMAIL_TEMPLATE
1694
1695 Specifies the path to the template for the email providing the code for authentication.
1696
1697 Default: ``"security/email/us_instructions"``
1698
1699 .. versionadded:: 5.9.0
1700 .. py:data:: SECURITY_US_ENABLED_METHODS
1701
1702 Specifies the default enabled methods for unified signin authentication.
1703 Be aware that ``password`` only affects this :data:`SECURITY_US_SIGNIN_URL` endpoint.
1704 Removing it from here won't stop users from using the :data:`SECURITY_LOGIN_URL` endpoint
1705 (unless you replace the login endpoint using :py:data:`SECURITY_US_SIGNIN_REPLACES_LOGIN`).
1706
1707 This config variable defines which methods can be used to provide ``passcode`` data.
1708 :py:data:`SECURITY_USER_IDENTITY_ATTRIBUTES` defines which user model fields can be used as ``identity``.
1709
1710 Default: ``["password", "email", "authenticator", "sms"]`` - which are the only supported options.
1711
1712 .. py:data:: SECURITY_US_MFA_REQUIRED
1713
1714 A list of :data:`SECURITY_US_ENABLED_METHODS` that will require two-factor
1715 authentication. This is of course dependent on the settings of :py:data:`SECURITY_TWO_FACTOR`
1716 and :py:data:`SECURITY_TWO_FACTOR_REQUIRED`. Note that even with REQUIRED, only
1717 methods listed here will trigger a two-factor cycle.
1718
1719 Default: ``["password", "email"]``
1720
1721 .. py:data:: SECURITY_US_TOKEN_VALIDITY
1722
1723 Specifies the number of seconds access token/code is valid.
1724
1725 Default: ``120``
1726
1727 .. py:data:: SECURITY_US_EMAIL_SUBJECT
1728
1729 Sets the email subject when sending the verification code via email.
1730
1731 Default: ``_("Verification Code")``
1732
1733 .. py:data:: SECURITY_US_SETUP_WITHIN
1734
1735 Specifies how long until the setup token expires.
1736
1737 Default: ``timedelta(minutes=30)``
1738
1739 .. versionchanged:: 5.9.0
1740 Accepted value changed to a timedelta
1741
1742 .. py:data:: SECURITY_US_SIGNIN_REPLACES_LOGIN
1743
1744 If set, then the :py:data:`SECURITY_LOGIN_URL` will be registered to the ``us-signin`` endpoint.
1745 Doing this will mean that logout will properly redirect to the us-signin endpoint.
1746
1747 Default: ``False``
1748
1749
1750 Additional relevant configuration variables:
1751
1752 * :py:data:`SECURITY_USER_IDENTITY_ATTRIBUTES` - Defines the order and methods for parsing and validating identity.
1753 * :py:data:`SECURITY_PASSWORD_REQUIRED` - Can a user register w/o a password?
1754 * :py:data:`SECURITY_DEFAULT_REMEMBER_ME`
1755 * :py:data:`SECURITY_SMS_SERVICE` - When SMS is enabled in :py:data:`SECURITY_US_ENABLED_METHODS`.
1756 * :py:data:`SECURITY_SMS_SERVICE_CONFIG`
1757 * :py:data:`SECURITY_TOTP_SECRETS`
1758 * :py:data:`SECURITY_TOTP_ISSUER`
1759 * :py:data:`SECURITY_PHONE_REGION_DEFAULT`
1760 * :py:data:`SECURITY_LOGIN_ERROR_VIEW` - The user is redirected here if
1761 :py:data:`SECURITY_US_VERIFY_LINK_URL` has an error and the request is json and
1762 :py:data:`SECURITY_REDIRECT_BEHAVIOR` equals ``"spa"``.
1763 * :py:data:`SECURITY_FRESHNESS` - Used to protect /us-setup.
1764 * :py:data:`SECURITY_FRESHNESS_GRACE_PERIOD` - Used to protect /us-setup.
1765
1766 Username-Recovery
1767 -----------------
1768
1769 .. versionadded:: 5.6.0
1770
1771 .. py:data:: SECURITY_USERNAME_RECOVERY
1772
1773 Specifies whether username recovery is enabled. If set to ``True`` the UserModel
1774 must contain a column ``"username"``. Note that this feature is independent
1775 of the :py:data:`SECURITY_USERNAME_ENABLE` feature.
1776
1777 Default: ``False``.
1778
1779 .. py:data:: SECURITY_USERNAME_RECOVERY_URL
1780
1781 Specifies the username recovery URL.
1782
1783 Default: ``"/recover-username"``.
1784
1785 .. py:data:: SECURITY_EMAIL_SUBJECT_USERNAME_RECOVERY
1786
1787 Sets subject for the username recovery email.
1788
1789 Default: ``_("Your requested username")``.
1790
1791 .. py:data:: SECURITY_USERNAME_RECOVERY_TEMPLATE
1792
1793 Specifies the path to the template for the username recovery page.
1794
1795 Default: ``"security/recover_username.html"``.
1796 .. py:data:: SECURITY_USERNAME_RECOVERY_EMAIL_TEMPLATE
1797
1798 Specifies the path to the template for the email sent to recover
1799 a username.
1800
1801 Default: ``"security/email/username_recovery"``
1802
1803 .. versionadded:: 5.9.0
1804
1805 Change Username
1806 -----------------
1807
1808 .. versionadded:: 5.6.0
1809
1810 .. py:data:: SECURITY_CHANGE_USERNAME
1811
1812 Specifies whether change username feature is enabled.
1813 This feature should be used in conjunction with
1814 the :py:data:`SECURITY_USERNAME_ENABLE` feature.
1815
1816 Default: ``False``
1817
1818 .. py:data:: SECURITY_CHANGE_USERNAME_URL
1819
1820 Specifies the change username URL.
1821
1822 Default: ``"/change-username"``
1823
1824 .. py:data:: SECURITY_POST_CHANGE_USERNAME_VIEW
1825
1826 Specifies the view to redirect to after a user successfully changes their username.
1827 This value can be set to a URL or an endpoint name.
1828 If this value is ``None``, the user is redirected to the
1829 value of :data:`SECURITY_POST_LOGIN_VIEW`.
1830
1831 Default: ``None``
1832
1833 .. py:data:: SECURITY_SEND_USERNAME_CHANGE_EMAIL
1834
1835 If ``True`` then an email will be sent to the registered user upon
1836 successful change of their username.
1837
1838 Default: ``True``
1839
1840 .. py:data:: SECURITY_EMAIL_SUBJECT_USERNAME_CHANGE_NOTICE
1841
1842 Sets subject for the change username email.
1843
1844 Default: ``_("Your username has been changed")``
1845
1846 .. py:data:: SECURITY_CHANGE_USERNAME_TEMPLATE
1847
1848 Specifies the path to the template for the change username page.
1849
1850 Default: ``"security/change_username.html"``
1851
1852 .. py:data:: SECURITY_CHANGE_USERNAME_EMAIL_TEMPLATE
1853
1854 Specifies the path to the template for the email sent confirming
1855 a username change.
1856
1857 Default: ``"security/email/change_username_notice"``
1858
1859 .. versionadded:: 5.9.0
1860
1861 Additional relevant configuration variables:
1862
1863 * :py:data:`SECURITY_FRESHNESS` - Used to protect /change-username.
1864 * :py:data:`SECURITY_FRESHNESS_GRACE_PERIOD` - Used to protect /change-username.
1865
1866
1867 Passwordless
1868 -------------
1869
1870 This feature is DEPRECATED as of 5.0.0. Please use unified signin feature instead.
1871
1872 .. note::
1873 The passwordless feature DOES NOT support two-factor authentication.
1874
1875 .. py:data:: SECURITY_PASSWORDLESS
1876
1877 Specifies if Flask-Security should enable the passwordless login feature.
1878 If set to ``True``, users are not required to enter a password to login but are
1879 sent an email with a login link.
1880 **This feature is being replaced with a more generalized passwordless feature
1881 that includes using SMS or authenticator applications for generating codes.**
1882
1883 Default: ``False``.
1884
1885 .. py:data:: SECURITY_SEND_LOGIN_TEMPLATE
1886
1887 Specifies the path to the template for the send login instructions page for
1888 passwordless logins.
1889
1890 Default:``"security/send_login.html"``.
1891
1892 .. py:data:: SECURITY_EMAIL_TEMPLATE_PASSWORDLESS
1893
1894 Specifies the path to the template for the email sent providing the
1895 link to sign in.
1896
1897 Default: ``"security/email/login_instructions"``
1898
1899 .. versionadded:: 5.9.0
1900
1901 .. py:data:: SECURITY_EMAIL_SUBJECT_PASSWORDLESS
1902
1903 Sets the subject for the passwordless feature.
1904
1905 Default: ``_("Login instructions")``.
1906
1907 .. py:data:: SECURITY_LOGIN_WITHIN
1908
1909 Specifies how long until the login link expires.
1910
1911 Default: ``timedelta(days=1)``.
1912
1913 .. versionchanged:: 5.9.0
1914 Accepted value changed to a timedelta
1915
1916 .. py:data:: SECURITY_LOGIN_ERROR_VIEW
1917
1918 Specifies the view/URL to redirect to after the following login/authentication errors:
1919
1920 * GET passwordless link where the link is expired/incorrect
1921 * GET unified sign in magic link when there is an error.
1922 * GET on oauthresponse where there was an OAuth protocol error.
1923 * GET on oauthresponse where the returned identity isn't registered.
1924
1925 This is only valid if :py:data:`SECURITY_REDIRECT_BEHAVIOR` == ``"spa"``.
1926 Query params in the redirect will contain the error.
1927
1928 Default: ``None``.
1929
1930 Trackable
1931 ----------
1932 .. py:data:: SECURITY_TRACKABLE
1933
1934 Specifies if Flask-Security should track basic user login statistics. If set to ``True``, ensure your
1935 models have the required fields/attributes and make sure to commit changes after calling
1936 ``login_user``. Be sure to use `ProxyFix <https://werkzeug.palletsprojects.com/en/stable/middleware/proxy_fix/>`_ if you are using a proxy.
1937
1938 Default: ``False``
1939
1940 WebAuthn/Passkeys
1941 -----------------
1942
1943 .. versionadded:: 5.0.0
1944
1945 .. py:data:: SECURITY_WEBAUTHN
1946
1947 To enable this feature - set this to ``True``. Please see :ref:`models_topic` for
1948 required additions to your database models.
1949
1950 Default: ``False``
1951
1952 .. py:data:: SECURITY_WAN_REGISTER_URL
1953
1954 Endpoint for registering WebAuthn credentials/passkeys.
1955
1956 Default: ``"/wan-register"``
1957
1958 .. py:data:: SECURITY_WAN_SIGNIN_URL
1959
1960 Endpoint for signing in using a WebAuthn credential/passkey.
1961
1962 Default: ``"/wan-signin"``
1963
1964 .. py:data:: SECURITY_WAN_DELETE_URL
1965
1966 Endpoint for removing a WebAuthn credential/passkey.
1967
1968 Default: ``"/wan-delete"``
1969
1970 .. py:data:: SECURITY_WAN_VERIFY_URL
1971
1972 Endpoint for reauthenticating using a WebAuthn credential/passkey.
1973
1974 Default: ``"/wan-verify"``
1975
1976 .. py:data:: SECURITY_WAN_POST_REGISTER_VIEW
1977
1978 Specifies the view to redirect to after a user successfully registers a new WebAuthn credential/passkey (non-json).
1979 This value can be set to a URL or an endpoint name.
1980
1981 Default: ``".wan-register"``
1982
1983 .. py:data:: SECURITY_WAN_REGISTER_TEMPLATE
1984
1985 Default: ``"security/wan_register.html"``
1986
1987 .. py:data:: SECURITY_WAN_SIGNIN_TEMPLATE
1988
1989 Default: ``"security/wan_signin.html"``
1990
1991 .. py:data:: SECURITY_WAN_VERIFY_TEMPLATE
1992
1993 Default: ``"security/wan_verify.html"``
1994
1995
1996 .. py:data:: SECURITY_WAN_RP_NAME
1997
1998 The Relying Party (that's us!) name passed as part of credential
1999 creation. Defined in the `spec <https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#dictionary-pkcredentialentity>`_.
2000
2001 Default: ``"My Flask App"``
2002
2003 .. py:data:: SECURITY_WAN_REGISTER_WITHIN
2004
2005 Specifies how long until the passkey registration token expires.
2006
2007 Default: ``timedelta(minutes=30)``
2008
2009 .. versionchanged:: 5.9.0
2010 Accepted value changed to a timedelta
2011
2012 .. py:data:: SECURITY_WAN_REGISTER_TIMEOUT
2013
2014 Specifies the timeout that is passed as part of PublicKeyCredentialCreationOptions.
2015 In milliseconds.
2016
2017 Default: ``60000``
2018
2019 .. py:data:: SECURITY_WAN_SIGNIN_WITHIN
2020
2021 Specifies how long until the passkey signin token expires.
2022
2023 Default: ``timedelta(minutes=1)``
2024
2025 .. versionchanged:: 5.9.0
2026 Accepted value changed to a timedelta
2027
2028 .. py:data:: SECURITY_WAN_SIGNIN_TIMEOUT
2029
2030 Specifies the timeout that is passed as part of PublicKeyCredentialRequestOptions.
2031 In milliseconds.
2032
2033 Default: ``60000``
2034
2035 .. py:data:: SECURITY_WAN_ALLOW_AS_FIRST_FACTOR
2036
2037 If True then a WebAuthn credential/passkey may be registered for use as the first (or only)
2038 authentication factor. This will set the default ``AuthenticatorSelectionCriteria``
2039 to require a cross-platform key.
2040
2041 Default: ``True``
2042
2043 .. py:data:: SECURITY_WAN_ALLOW_AS_MULTI_FACTOR
2044
2045 If True then a WebAuthn credential/passkey can be used
2046 as both a primary and a secondary factor. This requires that the key
2047 supports 'UserVerification'.
2048
2049 Default: ``True``
2050
2051 .. py:data:: SECURITY_WAN_ALLOW_USER_HINTS
2052
2053 If True then an unauthenticated user can request a list of registered
2054 WebAuthn credentials/passkeys. This allows the use of non-resident (non-discoverable)
2055 keys, but has the possible security concern that it allows 'user discovery'.
2056 Look at https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#sctn-username-enumeration
2057 for a good writeup.
2058
2059 If this is ``False`` and :py:data:`SECURITY_WAN_ALLOW_AS_FIRST_FACTOR` is ``True``
2060 (the default) then by default, ``AuthenticatorSelectionCriteria`` will be set
2061 to require a Resident key.
2062
2063 Default: ``True``
2064
2065 .. py:data:: SECURITY_WAN_ALLOW_AS_VERIFY
2066
2067 Sets which type of WebAuthn security credential, if any, may be used for
2068 reauthentication/verify events. This is a list with possible values:
2069
2070 - ``"first"`` - just credentials/passkeys registered as "first" usage are allowed
2071 - ``"secondary"`` - just credentials/passkeys registered as "secondary" are allowed
2072
2073 If list is empty or ``None`` WebAuthn credentials/passkeys aren't allowed. This also means that the
2074 :py:data:`SECURITY_WAN_VERIFY_URL` endpoint won't be registered.
2075
2076 Default: ``["first", "secondary"]``
2077
2078 .. py:data:: SECURITY_WAN_NAME_ALLOWED_CHARS
2079
2080 Define which unicode categories are used to validate webauthn/passkey
2081 names.
2082
2083 Default: ``["L", "N", "Pc", "Pd", "Zs"]``
2084
2085 .. versionadded:: 5.9.0
2086
2087 .. py:data:: SECURITY_WAN_NAME_MAX_LENGTH
2088
2089 Define maximum length of the webauthn/passkey name. This should correspond
2090 to the DB model.
2091
2092 Default: ``64``
2093
2094 .. versionadded:: 5.9.0
2095
2096 Additional relevant configuration variables:
2097
2098 * :py:data:`SECURITY_FRESHNESS` - Used to protect /wan-register and /wan-delete.
2099 * :py:data:`SECURITY_FRESHNESS_GRACE_PERIOD` - Used to protect /wan-register and /wan-delete.
2100
2101 Recovery Codes
2102 --------------
2103
2104 .. versionadded:: 5.0.0
2105
2106 .. py:data:: SECURITY_MULTI_FACTOR_RECOVERY_CODES
2107
2108 To enable this feature - set this to ``True``. Please see :ref:`models_topic` for
2109 required additions to your database models. This enables a user to generate and
2110 use a recovery code for two-factor authentication. This works for all two-factor
2111 mechanisms - including WebAuthn. Note that these code are single use and
2112 the user should be advised to write them down and store in a safe place.
2113
2114 .. py:data:: SECURITY_MULTI_FACTOR_RECOVERY_CODES_N
2115
2116 How many recovery codes to generate.
2117
2118 Default:: ``5``
2119
2120 .. py:data:: SECURITY_MULTI_FACTOR_RECOVERY_CODES_URL
2121
2122 Endpoint for displaying and generating recovery codes.
2123
2124 Default: ``"/mf-recovery-codes"``
2125
2126 .. py:data:: SECURITY_MULTI_FACTOR_RECOVERY_CODES_TEMPLATE
2127
2128 Default: ``"security/mf_recovery_codes.html"``
2129
2130 .. py:data:: SECURITY_MULTI_FACTOR_RECOVERY_URL
2131
2132 Endpoint for entering a recovery code.
2133
2134 Default: ``"/mf-recovery"``
2135
2136 .. py:data:: SECURITY_MULTI_FACTOR_RECOVERY_TEMPLATE
2137
2138 Default: ``"security/mf_recovery.html"``
2139
2140 .. py:data:: SECURITY_MULTI_FACTOR_RECOVERY_CODES_KEYS
2141
2142 A list of keys used to encrypt the recovery codes at rest (i.e. in the database).
2143 The default implementation uses cryptography.fernet (https://cryptography.io/en/latest/fernet/#cryptography.fernet.Fernet)
2144 - so the keys should be generated by::
2145
2146 from cryptography.fernet import Fernet
2147 key = Fernet.generate_key()
2148
2149 Multiple keys can be configured allowing for key rotation.
2150
2151 Default: ``None`` - recovery codes will NOT be encrypted on disk
2152
2153 .. versionadded:: 5.1.0
2154
2155 .. py:data:: SECURITY_MULTI_FACTOR_RECOVERY_CODE_TTL
2156
2157 An integer passed to decrypt specifying the maximum age of the code.
2158
2159 Default: ``None`` - no TTL will be enforced.
2160
2161 .. versionadded:: 5.1.0
2162
2163 Additional relevant configuration variables:
2164
2165 * :py:data:`SECURITY_FRESHNESS` - Used to protect /mf-recovery-codes.
2166 * :py:data:`SECURITY_FRESHNESS_GRACE_PERIOD` - Used to protect /mf-recovery-codes.
2167 * :py:data:`SECURITY_TOTP_SECRETS` - TOTP/passlib is used to generate the codes.
2168 * :py:data:`SECURITY_TOTP_ISSUER`
2169
2170 Social Login (OAuth)
2171 --------------------
2172 This integrates Flask-Security with authlib. Be sure to specify authlib in
2173 your dependency file.
2174
2175 .. versionadded:: 5.1.0
2176
2177 .. py:data:: SECURITY_OAUTH_ENABLE
2178
2179 To enable using external OAuth providers - set this to ``True``.
2180
2181 .. py:data:: SECURITY_OAUTH_BUILTIN_PROVIDERS
2182
2183 A list of built-in providers to register.
2184
2185 Default: ``["google", "github"]``
2186
2187 .. py:data:: SECURITY_OAUTH_START_URL
2188
2189 Endpoint for starting an OAuth authentication operation.
2190
2191 Default: ``"/login/oauthstart"``
2192
2193 .. py:data:: SECURITY_OAUTH_RESPONSE_URL
2194
2195 Endpoint used as OAuth redirect.
2196
2197 Default: ``"/login/oauthresponse"``
2198
2199 .. py:data:: SECURITY_POST_OAUTH_LOGIN_VIEW
2200
2201 Specifies the view/URL to redirect to after a successful authentication (login)
2202 using social login (OAuth).
2203 This is only valid if :py:data:`SECURITY_REDIRECT_BEHAVIOR` == ``"spa"``.
2204 Query params in the redirect will contain `identity` and `email`.
2205
2206 Default: ``None``.
2207
2208 .. versionadded:: 5.4.0
2209
2210 .. py:data:: SECURITY_OAUTH_VERIFY_START_URL
2211
2212 Endpoint for starting an OAuth reauthentication/verify operation.
2213
2214 Default: ``"/login/oauth-verify-start"``
2215
2216 .. versionadded:: 5.8.0
2217
2218 .. py:data:: SECURITY_OAUTH_VERIFY_RESPONSE_URL
2219
2220 Endpoint used as the OAuth verify redirect.
2221
2222 Default: ``"/login/oauth-verify-response"``
2223
2224 .. versionadded:: 5.8.0
2225
2226 .. py:data:: SECURITY_POST_OAUTH_VERIFY_VIEW
2227
2228 Specifies the view/URL to redirect to after a successful reauthentication (verify)
2229 using social login/oauth.
2230 This is only valid if :py:data:`SECURITY_REDIRECT_BEHAVIOR` == ``"spa"``.
2231 Query params in the redirect will contain `identity` and `email`.
2232
2233 Default: ``None``.
2234
2235 .. versionadded:: 5.8.0
2236
2237 .. py:data:: SECURITY_VERIFY_ERROR_VIEW
2238
2239 Specifies the view/URL to redirect to after the following login/authentication errors:
2240
2241 * GET on oauth-verify-response where there was an OAuth protocol error.
2242 * GET on oauth-verify-response where the returned identity isn't registered.
2243
2244 This is only valid if :py:data:`SECURITY_REDIRECT_BEHAVIOR` == ``"spa"``.
2245 Query params in the redirect will contain the error type and message.
2246
2247 Default: ``None``.
2248
2249 .. versionadded:: 5.8.0
2250
2251 Refresh Tokens
2252 ---------------
2253
2254 .. versionadded:: 5.9.0
2255
2256 .. py:data:: SECURITY_REFRESH_TOKEN
2257
2258 Specifies if Flask-Security should enable refresh token support.
2259
2260 Default: ``False``
2261 .. py:data:: SECURITY_REFRESH_TOKEN_URL
2262
2263 Specifies the URL used to get new auth_tokens using an existing
2264 refresh token
2265
2266 Default: ``"/refresh-token"``
2267 .. py:data:: SECURITY_REFRESH_TOKEN_MAX_AGE
2268
2269 Specifies a timedelta used to compute the refresh tokens expiration date.
2270
2271 Default: ``timedelta(days=90)``
2272 .. py:data:: SECURITY_REFRESH_TOKEN_MAX_IDLE
2273
2274 Specifies a timedelta used to compute the date the refresh token will be
2275 considered expired due to non-use.
2276
2277 Default: ``timedelta(days=7)``
2278 .. py:data:: SECURITY_REFRESH_TOKEN_CLEANUP_EXPIRED
2279
2280 If True then expired refresh tokens database trackers will be deleted
2281 whenever the user creates a new one (re-authenticates)
2282
2283 Default: ``True``
2284 .. py:data:: SECURITY_REFRESH_TOKEN_CLEANUP_REVOKED
2285
2286 If True then revoked refresh tokens database trackers will be deleted
2287 whenever the user creates a new one (re-authenticates)
2288
2289 Default: ``False``
2290 .. py:data:: SECURITY_REFRESH_COOKIE_NAME
2291
2292 If set then refresh tokens will be returned in a cookie rather than as
2293 part of the JSON response. Upon logout, the cookie will be deleted.
2294
2295 Default: ``"fs_refresh"``
2296
2297 .. py:data:: SECURITY_REFRESH_TOKEN_COOKIE
2298
2299 A dict that defines the parameters required to
2300 set the refresh token cookie.
2301 The complete set of parameters is described in Flask's `set_cookie`_ documentation.
2302 ``"httponly"`` should ALWAYS be set.
2303
2304 Default: ``{"samesite": "Strict", "httponly": True, "secure": True}``
2305
2306 Feature Flags
2307 -------------
2308 All feature flags. By default all are ``False``/not enabled.
2309
2310 * :py:data:`SECURITY_CHANGE_EMAIL`
2311 * :py:data:`SECURITY_CHANGE_USERNAME`
2312 * :py:data:`SECURITY_CONFIRMABLE`
2313 * :py:data:`SECURITY_REGISTERABLE`
2314 * :py:data:`SECURITY_RECOVERABLE`
2315 * :py:data:`SECURITY_TRACKABLE`
2316 * :py:data:`SECURITY_PASSWORDLESS`
2317 * :py:data:`SECURITY_CHANGEABLE`
2318 * :py:data:`SECURITY_TWO_FACTOR`
2319 * :py:data:`SECURITY_UNIFIED_SIGNIN`
2320 * :py:data:`SECURITY_USERNAME_RECOVERY`
2321 * :py:data:`SECURITY_WEBAUTHN`
2322 * :py:data:`SECURITY_MULTI_FACTOR_RECOVERY_CODES`
2323 * :py:data:`SECURITY_OAUTH_ENABLE`
2324 * :py:data:`SECURITY_REFRESH_TOKEN`
2325
2326 URLs and Views
2327 --------------
2328 A list of all URLs and Views:
2329
2330 * :py:data:`SECURITY_LOGIN_URL` ``"/login"``
2331 * :py:data:`SECURITY_LOGOUT_URL` ``"/logout"``
2332 * :py:data:`SECURITY_VERIFY_URL` ``"/verify"``
2333 * :py:data:`SECURITY_REGISTER_URL` ``"/register"``
2334 * :py:data:`SECURITY_CHANGE_EMAIL_URL` ``"change-email"``
2335 * :py:data:`SECURITY_CHANGE_EMAIL_CONFIRM_URL` ``"/change-email-confirm"``
2336 * :py:data:`SECURITY_CHANGE_USERNAME_URL` ``"change-username"``
2337 * :py:data:`SECURITY_RESET_URL` ``"/reset"``
2338 * :py:data:`SECURITY_CHANGE_URL` ``"/change"``
2339 * :py:data:`SECURITY_CONFIRM_URL` ``"/confirm"``
2340 * :py:data:`SECURITY_MULTI_FACTOR_RECOVERY_CODES_URL` ``"/mf-recovery-codes"``
2341 * :py:data:`SECURITY_MULTI_FACTOR_RECOVERY_URL` ``"/mf-recovery"``
2342 * :py:data:`SECURITY_OAUTH_START_URL` ``"/login/oauthstart"``
2343 * :py:data:`SECURITY_OAUTH_RESPONSE_URL` ``"/login/oauthresponse"``
2344 * :py:data:`SECURITY_OAUTH_VERIFY_START_URL` ``"/login/oauth-verify-start"``
2345 * :py:data:`SECURITY_OAUTH_VERIFY_RESPONSE_URL` ``"/login/oauth-verify-response"``
2346 * :py:data:`SECURITY_TWO_FACTOR_SELECT_URL` ``"/tf-select"``
2347 * :py:data:`SECURITY_TWO_FACTOR_SETUP_URL` ``"/tf-setup"``
2348 * :py:data:`SECURITY_TWO_FACTOR_TOKEN_VALIDATION_URL` ``"/tf-validate"``
2349 * :py:data:`SECURITY_TWO_FACTOR_RESCUE_URL` ``"/tf-rescue"``
2350 * :py:data:`SECURITY_TWO_FACTOR_ERROR_VIEW`
2351 * :py:data:`SECURITY_TWO_FACTOR_POST_SETUP_VIEW`
2352 * :py:data:`SECURITY_POST_LOGIN_VIEW`
2353 * :py:data:`SECURITY_POST_LOGOUT_VIEW`
2354 * :py:data:`SECURITY_CONFIRM_ERROR_VIEW`
2355 * :py:data:`SECURITY_POST_REGISTER_VIEW`
2356 * :py:data:`SECURITY_POST_CONFIRM_VIEW`
2357 * :py:data:`SECURITY_POST_RESET_VIEW`
2358 * :py:data:`SECURITY_POST_CHANGE_VIEW`
2359 * :py:data:`SECURITY_POST_OAUTH_LOGIN_VIEW`
2360 * :py:data:`SECURITY_POST_OAUTH_VERIFY_VIEW`
2361 * :py:data:`SECURITY_UNAUTHORIZED_VIEW`
2362 * :py:data:`SECURITY_RESET_VIEW`
2363 * :py:data:`SECURITY_RESET_ERROR_VIEW`
2364 * :py:data:`SECURITY_LOGIN_ERROR_VIEW`
2365 * :py:data:`SECURITY_USERNAME_RECOVERY_URL`
2366 * :py:data:`SECURITY_REFRESH_TOKEN_URL` ``"/refresh-token"``
2367 * :py:data:`SECURITY_US_SIGNIN_URL`
2368 * :py:data:`SECURITY_US_SETUP_URL`
2369 * :py:data:`SECURITY_US_SIGNIN_SEND_CODE_URL`
2370 * :py:data:`SECURITY_US_VERIFY_LINK_URL`
2371 * :py:data:`SECURITY_US_VERIFY_URL`
2372 * :py:data:`SECURITY_US_VERIFY_SEND_CODE_URL`
2373 * :py:data:`SECURITY_US_POST_SETUP_VIEW`
2374 * :py:data:`SECURITY_VERIFY_ERROR_VIEW`
2375 * :py:data:`SECURITY_WAN_REGISTER_URL`
2376 * :py:data:`SECURITY_WAN_SIGNIN_URL`
2377 * :py:data:`SECURITY_WAN_DELETE_URL`
2378 * :py:data:`SECURITY_WAN_VERIFY_URL`
2379 * :py:data:`SECURITY_WAN_POST_REGISTER_VIEW`
2380
2381 Template Paths
2382 --------------
2383 The list of all views templates:
2384
2385 * :py:data:`SECURITY_FORGOT_PASSWORD_TEMPLATE`
2386 * :py:data:`SECURITY_LOGIN_USER_TEMPLATE`
2387 * :py:data:`SECURITY_LOGOUT_USER_TEMPLATE`
2388 * :py:data:`SECURITY_VERIFY_TEMPLATE`
2389 * :py:data:`SECURITY_REGISTER_USER_TEMPLATE`
2390 * :py:data:`SECURITY_RESET_PASSWORD_TEMPLATE`
2391 * :py:data:`SECURITY_CHANGE_PASSWORD_TEMPLATE`
2392 * :py:data:`SECURITY_CHANGE_EMAIL_TEMPLATE`
2393 * :py:data:`SECURITY_CHANGE_USERNAME_TEMPLATE`
2394 * :py:data:`SECURITY_MULTI_FACTOR_RECOVERY_TEMPLATE`
2395 * :py:data:`SECURITY_MULTI_FACTOR_RECOVERY_CODES_TEMPLATE`
2396 * :py:data:`SECURITY_SEND_CONFIRMATION_TEMPLATE`
2397 * :py:data:`SECURITY_SEND_LOGIN_TEMPLATE`
2398 * :py:data:`SECURITY_TWO_FACTOR_VERIFY_CODE_TEMPLATE`
2399 * :py:data:`SECURITY_TWO_FACTOR_SELECT_TEMPLATE`
2400 * :py:data:`SECURITY_TWO_FACTOR_SETUP_TEMPLATE`
2401 * :py:data:`SECURITY_USERNAME_RECOVERY_TEMPLATE`
2402 * :py:data:`SECURITY_US_SIGNIN_TEMPLATE`
2403 * :py:data:`SECURITY_US_SETUP_TEMPLATE`
2404 * :py:data:`SECURITY_US_VERIFY_TEMPLATE`
2405 * :py:data:`SECURITY_WAN_REGISTER_TEMPLATE`
2406 * :py:data:`SECURITY_WAN_SIGNIN_TEMPLATE`
2407 * :py:data:`SECURITY_WAN_VERIFY_TEMPLATE`
2408
2409 The list of all email templates:
2410
2411 * :py:data:`SECURITY_CHANGE_EMAIL_EMAIL_TEMPLATE` ``"security/email/change_email_instructions"``
2412 * :py:data:`SECURITY_EMAIL_TEMPLATE_PASSWORD_CHANGE_NOTICE` ``"security/email/change_notice"``
2413 * :py:data:`SECURITY_EMAIL_TEMPLATE_CONFIRM` ``"security/email/confirmation_instructions"``
2414 * :py:data:`SECURITY_EMAIL_TEMPLATE_PASSWORD_RESET` ``"security/email/reset_instructions"``
2415 * :py:data:`SECURITY_EMAIL_TEMPLATE_PASSWORD_RESET_NOTICE` ``"security/email/reset_notice"``
2416 * :py:data:`SECURITY_EMAIL_TEMPLATE_PASSWORDLESS` ``"security/email/login_instructions"``
2417 * :py:data:`SECURITY_REGISTER_EMAIL_TEMPLATE` ``"security/email/welcome"``
2418 * :py:data:`SECURITY_REGISTER_EMAIL_EXISTING_USERNAME_TEMPLATE` ``"security/email/welcome_existing_username"``
2419 * :py:data:`SECURITY_REGISTER_EMAIL_EXISTING_TEMPLATE` ``"security/email/welcome_existing"``
2420 * :py:data:`SECURITY_TWO_FACTOR_EMAIL_TEMPLATE` ``"security/email/two_factor_instructions"``
2421 * :py:data:`SECURITY_TWO_FACTOR_RESCUE_EMAIL_TEMPLATE` ``"security/email/two_factor_rescue"``
2422 * :py:data:`SECURITY_US_EMAIL_TEMPLATE` ``"security/email/us_instructions"``
2423 * :py:data:`SECURITY_CHANGE_USERNAME_EMAIL_TEMPLATE` ``"security/email/change_username_notice"``
2424 * :py:data:`SECURITY_USERNAME_RECOVERY_EMAIL_TEMPLATE` ``"security/email/username_recovery"``
2425
2426
2427 Messages
2428 -------------
2429
2430 The following are the messages Flask-Security uses. They are tuples; the first
2431 element is the message and the second element is the error level.
2432
2433 The default messages and error levels can be found in ``core.py``.
2434
2435 * ``SECURITY_MSG_ALREADY_CONFIRMED``
2436 * ``SECURITY_MSG_API_ERROR``
2437 * ``SECURITY_MSG_ANONYMOUS_USER_REQUIRED``
2438 * ``SECURITY_MSG_CHANGE_EMAIL_EXPIRED``
2439 * ``SECURITY_MSG_CHANGE_EMAIL_CONFIRMED``
2440 * ``SECURITY_MSG_CHANGE_EMAIL_SENT``
2441 * ``SECURITY_MSG_CODE_HAS_BEEN_SENT``
2442 * ``SECURITY_MSG_CONFIRMATION_EXPIRED``
2443 * ``SECURITY_MSG_CONFIRMATION_REQUEST``
2444 * ``SECURITY_MSG_CONFIRMATION_REQUIRED``
2445 * ``SECURITY_MSG_CONFIRM_REGISTRATION``
2446 * ``SECURITY_MSG_DISABLED_ACCOUNT``
2447 * ``SECURITY_MSG_EMAIL_ALREADY_ASSOCIATED``
2448 * ``SECURITY_MSG_EMAIL_CONFIRMED``
2449 * ``SECURITY_MSG_EMAIL_NOT_PROVIDED``
2450 * ``SECURITY_MSG_FAILED_TO_SEND_CODE``
2451 * ``SECURITY_MSG_FORGOT_PASSWORD``
2452 * ``SECURITY_MSG_GENERIC_AUTHN_FAILED``
2453 * ``SECURITY_MSG_GENERIC_RECOVERY``
2454 * ``SECURITY_MSG_GENERIC_US_SIGNIN``
2455 * ``SECURITY_MSG_IDENTITY_ALREADY_ASSOCIATED``
2456 * ``SECURITY_MSG_IDENTITY_NOT_REGISTERED``
2457 * ``SECURITY_MSG_INVALID_CODE``
2458 * ``SECURITY_MSG_INVALID_CONFIRMATION_TOKEN``
2459 * ``SECURITY_MSG_INVALID_EMAIL_ADDRESS``
2460 * ``SECURITY_MSG_INVALID_LOGIN_TOKEN``
2461 * ``SECURITY_MSG_INVALID_INPUT``
2462 * ``SECURITY_MSG_INVALID_INPUT_LENGTH``
2463 * ``SECURITY_MSG_INVALID_PASSWORD``
2464 * ``SECURITY_MSG_INVALID_PASSWORD_CODE``
2465 * ``SECURITY_MSG_INVALID_RECOVERY_CODE``
2466 * ``SECURITY_MSG_INVALID_REDIRECT``
2467 * ``SECURITY_MSG_INVALID_RESET_PASSWORD_TOKEN``
2468 * ``SECURITY_MSG_LOGIN``
2469 * ``SECURITY_MSG_LOGIN_EMAIL_SENT``
2470 * ``SECURITY_MSG_LOGIN_EXPIRED``
2471 * ``SECURITY_MSG_NO_RECOVERY_CODES_SETUP``
2472 * ``SECURITY_MSG_OAUTH_HANDSHAKE_ERROR``
2473 * ``SECURITY_MSG_PASSWORDLESS_LOGIN_SUCCESSFUL``
2474 * ``SECURITY_MSG_PASSWORD_BREACHED``
2475 * ``SECURITY_MSG_PASSWORD_BREACHED_SITE_ERROR``
2476 * ``SECURITY_MSG_PASSWORD_CHANGE``
2477 * ``SECURITY_MSG_PASSWORD_INVALID_LENGTH``
2478 * ``SECURITY_MSG_PASSWORD_IS_THE_SAME``
2479 * ``SECURITY_MSG_PASSWORD_MISMATCH``
2480 * ``SECURITY_MSG_PASSWORD_NOT_PROVIDED``
2481 * ``SECURITY_MSG_PASSWORD_REQUIRED``
2482 * ``SECURITY_MSG_PASSWORD_RESET``
2483 * ``SECURITY_MSG_PASSWORD_RESET_EXPIRED``
2484 * ``SECURITY_MSG_PASSWORD_RESET_NO_LOGIN``
2485 * ``SECURITY_MSG_PASSWORD_RESET_REQUEST``
2486 * ``SECURITY_MSG_PASSWORD_TOO_SIMPLE``
2487 * ``SECURITY_MSG_PHONE_INVALID``
2488 * ``SECURITY_MSG_REAUTHENTICATION_REQUIRED``
2489 * ``SECURITY_MSG_REAUTHENTICATION_SUCCESSFUL``
2490 * ``SECURITY_MSG_REFRESH``
2491 * ``SECURITY_REFRESH_TOKEN_INVALID``
2492 * ``SECURITY_MSG_RETYPE_PASSWORD_MISMATCH``
2493 * ``SECURITY_MSG_TWO_FACTOR_INVALID_TOKEN``
2494 * ``SECURITY_MSG_TWO_FACTOR_LOGIN_SUCCESSFUL``
2495 * ``SECURITY_MSG_TWO_FACTOR_CHANGE_METHOD_SUCCESSFUL``
2496 * ``SECURITY_MSG_TWO_FACTOR_PERMISSION_DENIED``
2497 * ``SECURITY_MSG_TWO_FACTOR_METHOD_NOT_AVAILABLE``
2498 * ``SECURITY_MSG_TWO_FACTOR_SETUP_EXPIRED``
2499 * ``SECURITY_MSG_TWO_FACTOR_DISABLED``
2500 * ``SECURITY_MSG_UNAUTHORIZED``
2501 * ``SECURITY_MSG_UNAUTHENTICATED``
2502 * ``SECURITY_MSG_US_METHOD_NOT_AVAILABLE``
2503 * ``SECURITY_MSG_US_SETUP_EXPIRED``
2504 * ``SECURITY_MSG_US_SETUP_SUCCESSFUL``
2505 * ``SECURITY_MSG_US_SPECIFY_IDENTITY``
2506 * ``SECURITY_MSG_USE_CODE``
2507 * ``SECURITY_MSG_USER_DOES_NOT_EXIST``
2508 * ``SECURITY_MSG_USERNAME_CHANGE``
2509 * ``SECURITY_MSG_USERNAME_INVALID_LENGTH``
2510 * ``SECURITY_MSG_USERNAME_DISALLOWED_CHARACTERS``
2511 * ``SECURITY_MSG_USERNAME_NOT_PROVIDED``
2512 * ``SECURITY_MSG_USERNAME_ALREADY_ASSOCIATED``
2513 * ``SECURITY_MSG_USERNAME_RECOVERY_REQUEST``
2514 * ``SECURITY_MSG_WEBAUTHN_EXPIRED``
2515 * ``SECURITY_MSG_WEBAUTHN_NAME_REQUIRED``
2516 * ``SECURITY_MSG_WEBAUTHN_NAME_INUSE``
2517 * ``SECURITY_MSG_WEBAUTHN_NAME_NOT_FOUND``
2518 * ``SECURITY_MSG_WEBAUTHN_NAME_DISALLOWED_CHARACTERS``
2519 * ``SECURITY_MSG_WEBAUTHN_CREDENTIAL_DELETED``
2520 * ``SECURITY_MSG_WEBAUTHN_REGISTER_SUCCESSFUL``
2521 * ``SECURITY_MSG_WEBAUTHN_CREDENTIAL_ID_INUSE``
2522 * ``SECURITY_MSG_WEBAUTHN_UNKNOWN_CREDENTIAL_ID``
2523 * ``SECURITY_MSG_WEBAUTHN_ORPHAN_CREDENTIAL_ID``
2524 * ``SECURITY_MSG_WEBAUTHN_NO_VERIFY``
2525 * ``SECURITY_MSG_WEBAUTHN_CREDENTIAL_WRONG_USAGE``
2526 * ``SECURITY_MSG_WEBAUTHN_MISMATCH_USER_HANDLE``
2527
2528 .. _passlib's CryptoContext: https://passlib.readthedocs.io/en/stable/lib/passlib.context.html