Debian Codegraph @

docs/api.rst

raw
1 API
2 ===
3
4 The external (json/form) API is described `here`_
5
6 .. _here: _static/openapi_view.html
7
8
9 Core
10 ----
11 .. autoclass:: flask_security.Security
12 :members:
13
14 .. data:: flask_security.current_user
15
16 A proxy for the current user.
17
18 Protecting Views
19 ----------------
20 All Flask-Security decorators are compatible with Flask's async implementation.
21 This is accomplished by wrapping function calls with flask.ensure_async().
22 Please see `Flask async`_.
23
24 .. autofunction:: flask_security.anonymous_user_required
25
26 .. autofunction:: flask_security.http_auth_required
27
28 .. autofunction:: flask_security.auth_token_required
29
30 .. autofunction:: flask_security.auth_required
31
32 .. autofunction:: flask_security.roles_required
33
34 .. autofunction:: flask_security.roles_accepted
35
36 .. autofunction:: flask_security.permissions_required
37
38 .. autofunction:: flask_security.permissions_accepted
39
40 .. autofunction:: flask_security.unauth_csrf
41
42 .. autofunction:: flask_security.handle_csrf
43
44 User Object Helpers
45 -------------------
46 .. autoclass:: flask_security.UserMixin
47 :members:
48
49 .. autoclass:: flask_security.RoleMixin
50 :members:
51
52 .. autoclass:: flask_security.WebAuthnMixin
53 :members:
54
55
56 Datastores
57 ----------
58 .. autoclass:: flask_security.UserDatastore
59 :members:
60 :exclude-members: create_webauthn, find_user_from_webauthn,
61 mf_set_recovery_codes, mf_delete_recovery_code,
62 set_webauthn_user_handle,
63 us_get_totp_secrets, us_put_totp_secrets
64
65 .. autoclass:: flask_security.SQLAlchemyUserDatastore
66 :show-inheritance:
67
68 .. autoclass:: flask_security.FSQLALiteUserDatastore
69 :show-inheritance:
70
71 .. autoclass:: flask_security.SQLAlchemySessionUserDatastore
72 :show-inheritance:
73
74 .. autoclass:: flask_security.MongoEngineUserDatastore
75 :show-inheritance:
76
77 .. autoclass:: flask_security.PeeweeUserDatastore
78 :show-inheritance:
79
80 .. autoclass:: flask_security.PonyUserDatastore
81 :show-inheritance:
82
83 .. autoclass:: flask_security.datastore.SQLAlchemyDatastore
84
85 Internal class implementing DataStore interface.
86
87 .. autoclass:: flask_security.datastore.MongoEngineDatastore
88
89 Internal class implementing DataStore interface.
90
91 .. autoclass:: flask_security.datastore.PeeweeDatastore
92
93 Internal class implementing DataStore interface.
94
95 .. autoclass:: flask_security.datastore.PonyDatastore
96
97 Internal class implementing DataStore interface.
98
99 .. class:: User
100
101 The User model. This must be provided by the application.
102 See :ref:`Models <models_topic>`.
103
104 .. class:: Role
105
106 The Role model. This must be provided by the application.
107 See :ref:`Models <models_topic>`.
108
109 .. class:: WebAuthn
110
111 The WebAuthn model. This must be provided by the application.
112 See :ref:`Models <models_topic>`.
113
114 Packaged Models
115 ---------------
116 .. autoclass:: flask_security.models.fsqla.FsModels
117 :members:
118 .. autoclass:: flask_security.models.sqla.FsModels
119 :members:
120
121 Utils
122 -----
123 .. autofunction:: flask_security.lookup_identity
124
125 .. autofunction:: flask_security.login_user
126
127 .. autofunction:: flask_security.logout_user
128
129 .. autofunction:: flask_security.check_and_update_authn_fresh
130
131 .. autofunction:: flask_security.get_hmac
132
133 .. autofunction:: flask_security.get_request_attr
134
135 .. autofunction:: flask_security.verify_password
136
137 .. autofunction:: flask_security.verify_and_update_password
138
139 .. autofunction:: flask_security.hash_password
140
141 .. autofunction:: flask_security.admin_change_password
142
143 .. autofunction:: flask_security.uia_phone_mapper
144
145 .. autofunction:: flask_security.uia_email_mapper
146
147 .. autofunction:: flask_security.uia_username_mapper
148
149 .. autofunction:: flask_security.url_for_security
150
151 .. autofunction:: flask_security.send_mail
152
153 .. autofunction:: flask_security.check_and_get_token_status
154
155 .. autofunction:: flask_security.get_url
156
157 .. autofunction:: flask_security.password_length_validator
158
159 .. autofunction:: flask_security.password_complexity_validator
160
161 .. autofunction:: flask_security.password_breached_validator
162
163 .. autofunction:: flask_security.pwned
164
165 .. autofunction:: flask_security.unique_identity_attribute
166
167 .. autofunction:: flask_security.us_send_security_token
168
169 .. autofunction:: flask_security.tf_send_security_token
170
171 .. autoclass:: flask_security.AsaList
172
173 .. autoclass:: flask_security.SmsSenderBaseClass
174 :members: send_sms
175
176 .. autoclass:: flask_security.SmsSenderFactory
177 :members: createSender
178
179 .. py:class:: OauthCbType[oauth: OAuth, token: t.Any]
180
181 This callback is called when the OAuth
182 redirect happens. It must take the response from the provider and return
183 a tuple of <user_model_field_name, value> - which will be used
184 to look up the user in the datastore.
185
186 .. autoclass:: flask_security.OAuthGlue
187 :members: register_provider, register_provider_ext
188
189 .. autoclass:: flask_security.FsOAuthProvider
190 :members:
191
192
193 Extendable Classes
194 ------------------
195 Each of the following classes can be extended and passed in as part of
196 Security() instantiation.
197
198 .. autoclass:: flask_security.PhoneUtil
199 :members:
200 :special-members: __init__
201
202 .. autoclass:: flask_security.MailUtil
203 :members:
204 :special-members: __init__
205
206 .. autoclass:: flask_security.EmailValidateException
207
208 .. autoclass:: flask_security.PasswordUtil
209 :members:
210 :special-members: __init__
211
212 .. autoclass:: flask_security.MfRecoveryCodesUtil
213 :members:
214 :special-members: __init__
215
216 .. autoclass:: flask_security.UsernameUtil
217 :members:
218 :special-members: __init__
219
220 .. autoclass:: flask_security.WebauthnUtil
221 :members:
222 :special-members: __init__
223
224 .. autoclass:: flask_security.Totp
225 :members: get_last_counter, set_last_counter, generate_qrcode
226
227
228 Forms
229 -----
230
231 .. autoclass:: flask_security.ChangeEmailForm
232 .. autoclass:: flask_security.ChangePasswordForm
233 .. autoclass:: flask_security.ChangeUsernameForm
234 .. autoclass:: flask_security.ConfirmRegisterForm
235 .. autoclass:: flask_security.Form
236 .. autoclass:: flask_security.FormInfo
237 .. autoclass:: flask_security.ForgotPasswordForm
238 .. autoclass:: flask_security.LoginForm
239 .. autoclass:: flask_security.MfRecoveryCodesForm
240 .. autoclass:: flask_security.MfRecoveryForm
241 .. autoclass:: flask_security.PasswordlessLoginForm
242 .. autoclass:: flask_security.RegisterForm
243 .. autoclass:: flask_security.RegisterFormV2
244 .. autoclass:: flask_security.ResetPasswordForm
245 .. autoclass:: flask_security.SendConfirmationForm
246 .. autoclass:: flask_security.TwoFactorRescueForm
247 .. autoclass:: flask_security.TwoFactorSelectForm
248 .. autoclass:: flask_security.TwoFactorSetupForm
249 .. autoclass:: flask_security.TwoFactorVerifyCodeForm
250 .. autoclass:: flask_security.UnifiedSigninForm
251 .. autoclass:: flask_security.UnifiedSigninSetupForm
252 .. autoclass:: flask_security.UnifiedSigninSetupValidateForm
253 .. autoclass:: flask_security.UnifiedVerifyForm
254 .. autoclass:: flask_security.UsernameRecoveryForm
255 .. autoclass:: flask_security.VerifyForm
256 .. autoclass:: flask_security.WebAuthnDeleteForm
257 .. autoclass:: flask_security.WebAuthnRegisterForm
258 .. autoclass:: flask_security.WebAuthnRegisterResponseForm
259 .. autoclass:: flask_security.WebAuthnSigninForm
260 .. autoclass:: flask_security.WebAuthnSigninResponseForm
261 .. autoclass:: flask_security.WebAuthnVerifyForm
262
263 .. _signals_topic:
264
265 Signals
266 -------
267 See the `Flask documentation on signals`_ for information on how to use these
268 signals in your code.
269 All Flask-Security signals are compatible with Blinker's async implementation.
270 See `Blinker async`_
271
272 .. tip::
273
274 Remember to add ``**extra_args`` to your signature so that if we add
275 additional parameters in the future your code doesn't break.
276
277 See the documentation for the signals provided by the Flask-Login and
278 Flask-Principal extensions. In addition to those signals, Flask-Security
279 sends the following signals.
280
281 .. data:: user_authenticated
282
283 Sent when a user successfully authenticates. In addition to the app (which is the
284 sender), it is passed `user`, and `authn_via` arguments. The `authn_via` argument
285 specifies how the user authenticated - it will be a list with possible values
286 of ``password``, ``sms``, ``authenticator``, ``email``, ``confirm``, ``reset``,
287 ``register``, ``webauthn``, ``oauth``.
288
289 .. versionadded:: 3.4.0
290
291 .. data:: user_unauthenticated
292
293 Sent when a user accesses a protected endpoint but isn't properly authenticated.
294 It is sent as part of the `default_unauthn_handler` (:meth:`.Security.unauthn_handler`)
295 It is passed the app (which is the sender).
296
297 .. versionadded:: 5.4.0
298
299 .. data:: user_failed_authn
300
301 Sent from :py:meth:`.UserMixin.track_failed_authn` when a user fails authentication.
302 In addition to the app (which is the sender) it is passed:
303
304 * `user` - the user that failed authentication
305 * `endpoint` - the endpoint that was accessed
306 * `auth_type` - `password`, `code`, `passkey`
307 * `tfa` - True if this was a two factor authentication attempt
308
309 .. versionadded:: 5.8.0
310
311 .. data:: user_registered
312
313 Sent when a user registers on the site. In addition to the app (which is the
314 sender), it is passed `user`, `confirm_token` (deprecated), `confirmation_token` and `form_data` arguments.
315 `form_data` is a dictionary representation of registration form's content
316 received with the registration request.
317
318 .. data:: user_not_registered
319
320 Sent when a user attempts to register, but is already registered. This is ONLY sent
321 when :py:data:`SECURITY_RETURN_GENERIC_RESPONSES` is enabled. It is passed the
322 following arguments:
323
324 * `user` - The existing user model
325 * `existing_email` - True if attempting to register an existing email
326 * `existing_username`- True if attempting to register an existing username
327 * `form_data` - the entire contents of the posted request form
328
329 .. versionadded:: 5.0.0
330
331 .. data:: user_confirmed
332
333 Sent when a user is confirmed. In addition to the app (which is the
334 sender), it is passed a `user` argument.
335
336 .. data:: confirm_instructions_sent
337
338 Sent when a user requests confirmation instructions. In addition to the app
339 (which is the sender), it is passed a `user` and `confirmation_token` arguments.
340
341 .. data:: login_instructions_sent
342
343 Sent when passwordless login is used and user logs in. In addition to the app
344 (which is the sender), it is passed `user` and `login_token` arguments.
345
346 .. data:: password_reset
347
348 Sent when a user completes a password reset. In addition to the app (which is
349 the sender), it is passed a `user` argument.
350
351 .. data:: password_changed
352
353 Sent when a user completes a password change. In addition to the app (which is
354 the sender), it is passed a `user` argument.
355
356 .. data:: reset_password_instructions_sent
357
358 Sent when a user requests a password reset. In addition to the app (which is
359 the sender), it is passed `user`, `token` (deprecated), and `reset_token` arguments.
360
361 .. data:: change_email_instructions_sent
362
363 Sent when a user requests to change their registered email address. In addition to the
364 app (which is the sender) it is passed `user`, `token`, and `new_email`.
365
366 .. versionadded:: 5.5.0
367
368 .. data:: change_email_confirmed
369
370 Sent when a user has confirmed their new email address. In addition to the
371 app (which is the sender) it is passed `user`, `old_email`.
372
373 .. versionadded:: 5.5.0
374
375 .. data:: tf_code_confirmed
376
377 Sent when a user performs two-factor authentication login on the site. In
378 addition to the app (which is the sender), it is passed `user`
379 and `method` arguments.
380
381 .. versionadded:: 3.3.0
382
383 .. data:: tf_profile_changed
384
385 Sent when two-factor is used and user logs in. In addition to the app
386 (which is the sender), it is passed `user` and `method` arguments.
387
388 .. versionadded:: 3.3.0
389
390 .. data:: tf_disabled
391
392 Sent when two-factor is disabled. In addition to the app
393 (which is the sender), it is passed `user` argument.
394
395 .. versionadded:: 3.3.0
396
397 .. data:: tf_security_token_sent
398
399 Sent when a two factor security/access code is sent. In addition to the app
400 (which is the sender), it is passed `user`, `method`, `login_token` and `token` (deprecated) arguments.
401
402 .. versionadded:: 3.3.0
403
404 .. data:: username_changed
405
406 Sent when a username is successfully changed. In addition to the
407 app (which is the sender), it is passed the `user` and `old_username` arguments.
408
409 .. data:: username_recovery_email_sent
410
411 Sent when a username is successfully recovered and sent over email. In addition to the
412 app (which is the sender), it is passed the `user` argument.
413
414 .. versionadded:: 5.6.0
415
416 .. data:: us_security_token_sent
417
418 Sent when a unified sign in access code is sent. In addition to the app
419 (which is the sender), it is passed `user`, `method`, `token` (deprecated),
420 `login_token`,
421 `phone_number`, and `send_magic_link` arguments.
422
423 .. versionadded:: 3.4.0
424
425 .. data:: us_profile_changed
426
427 Sent when user completes changing their unified sign in profile. In addition to the app
428 (which is the sender), it is passed `user`, `methods`, and `delete` arguments.
429 `delete` will be set to ``True`` if the user removed a sign in option.
430
431 .. versionadded:: 3.4.0
432
433 .. versionchanged:: 5.0.0
434 Added delete argument and changed `method` to `methods` which is now a list.
435
436 .. data:: wan_registered
437
438 Sent when a WebAuthn credential was successfully created. In addition to the app
439 (which is the sender), it is passed `user` and `name` arguments.
440
441 .. versionadded:: 5.0.0
442
443 .. data:: wan_deleted
444
445 Sent when a WebAuthn credential was deleted. In addition to the app
446 (which is the sender), it is passed `user` and `name` arguments.
447
448 .. versionadded:: 5.0.0
449
450 .. _Flask async: https://flask.palletsprojects.com/en/3.0.x/async-await/#using-async-and-await
451 .. _Flask documentation on signals: https://flask.palletsprojects.com/en/2.3.x/signals/
452 .. _Blinker async: https://blinker.readthedocs.io/en/stable/#async-receivers