@@ -40,7 +40,7 @@ The provided models are versioned since they represent actual DB models, and any
4040changes require a schema migration (and perhaps a data migration). Applications
4141must specifically import the version they want (and handle any required migration).
4242
43- There are 2 available models - one when using Flask- SQLAlchemy and one when
43+ There are two available models - one when using Flask- SQLAlchemy and one when
4444using ' raw' sqlalchemy or Flask- SQLAlchemy- Lite.
4545
4646.. note::
@@ -49,7 +49,8 @@ using 'raw' sqlalchemy or Flask-SQLAlchemy-Lite.
4949
5050Flask- SQLAlchemy
5151^^^^^^^^^^^^^^^^
52- Your application code should import just the required version e.g.::
52+ Your application code should import just the required version e.g.:
53+ .. code- block:: python
5354
5455 from flask_security.models import fsqla_v3 as fsqla
5556 from flask_sqlalchemy import SQLAlchemy
@@ -71,7 +72,9 @@ DB instance. This is only needed if you use the packaged models.
7172
7273Flask- SQLAlchemy- Lite
7374^^^^^^^^^^^^^^^^^^^^^
74- Your application code should import just the required version e.g.::
75+ Your application code should import just the required version e.g.:
76+
77+ .. code- block:: python
7578
7679 from flask_security.models import sqla as sqla
7780 from flask_sqlalchemy_lite import SQLAlchemy
@@ -222,7 +225,12 @@ Flask-Security must be able to locate a User record based on a credential id.
222225 It is important that you maintain data consistency when deleting WebAuthn
223226 records or users.
224227
225- The ' WebAuthn' model requires the following fields:
228+ The `User` model needs the following additional field:
229+
230+ * `` fs_webauthn_user_handle`` (string, 64 bytes , unique).
231+ This is used as the `PublicKeyCredentialUserEntity` `id ` value.
232+
233+ The `WebAuthn` model requires the following fields:
226234
227235* `` id `` (primary key)
228236* `` credential_id`` (binary, 1024 bytes , indexed, non- nullable, unique)
@@ -239,58 +247,66 @@ The 'WebAuthn' model requires the following fields:
239247There needs to be a bi- directional relationship between the WebAuthn record and
240248the User record (since we need to look up the `` User`` based on a WebAuthn `` credential_id`` .
241249
242- ** For SQLAlchemy** ::
250+ ** For SQLAlchemy** :
243251
244- Add the following to the WebAuthn model (assuming your primary key is named `` id `` ):
252+ - Add the following to the WebAuthn model (assuming your primary key is named `` id `` ):
245253
246- @ declared_attr
247- def user_id(cls ) -> Mapped[int ]:
248- return mapped_column(
249- ForeignKey(" user.id" , ondelete = " CASCADE" )
250- )
254+ .. code- block:: python
251255
252- Add the following to the User model:
256+ @ declared_attr
257+ def user_id(cls ) -> Mapped[int ]:
258+ return mapped_column(
259+ ForeignKey(" user.id" , ondelete = " CASCADE" )
260+ )
253261
254- @ declared_attr
255- def webauthn(cls ):
256- return relationship(
257- " WebAuthn" , back_populates = " user" , cascade = " all, delete"
258- )
262+ - Add the following to the User model:
259263
260- ** For mongoengine ** ::
264+ .. code - block:: python
261265
262- Add the following to the WebAuthn model:
266+ @ declared_attr
267+ def webauthn(cls ):
268+ return relationship(
269+ " WebAuthn" , back_populates = " user" , cascade = " all, delete"
270+ )
271+
272+ ** For mongoengine** :
263273
264- user = ReferenceField(" User" )
265- def get_user_mapping(self ) -> dict[str , str ]:
266- """ Return the mapping from webauthn back to User"""
267- return dict (id = self .user.id)
274+ - Add the following to the WebAuthn model:
268275
269- Add the following to the User model:
276+ .. code - block:: python
270277
271- webauthn = ListField(ReferenceField(WebAuthn, reverse_delete_rule = PULL ), default = [])
278+ user = ReferenceField(" User" )
279+ def get_user_mapping(self ) -> dict[str , str ]:
280+ """ Return the mapping from webauthn back to User"""
281+ return dict (id = self .user.id)
272282
273- To make sure all WebAuthn objects are deleted if the User is deleted :
283+ - Add the following to the User model :
274284
275- User.register_delete_rule(WebAuthn, " user " , CASCADE )
285+ .. code - block:: python
276286
287+ webauthn = ListField(ReferenceField(WebAuthn, reverse_delete_rule = PULL ), default = [])
277288
278- ** For peewee** ::
289+ - To make sure all WebAuthn objects are deleted if the User is deleted:
290+
291+ .. code- block:: python
292+
293+ User.register_delete_rule(WebAuthn, " user" , CASCADE )
294+
295+
296+ ** For peewee** :
279297
280298 Add the following to the WebAuthn model:
281299
282- user = ForeignKeyField(User, backref = " webauthn" )
300+ .. code- block:: python
301+
302+ user = ForeignKeyField(User, backref = " webauthn" )
283303
284304 This will add a column called `` user_id`` that references the User model' s
285305 `` id `` primary key field. It will also create a virtual column `` webauthn``
286306 as part of the User model. Note that the default Peewee datastore implementation
287307 calls `` delete_instance(recursive = True )`` which correctly deals with ensuring
288308 that WebAuthn records get deleted if a User is deleted.
289309
290- The `User` model needs the following additional fields:
291-
292- * `` fs_webauthn_user_handle`` (string, 64 bytes , unique).
293- This is used as the `PublicKeyCredentialUserEntity` `id ` value.
294310
295311Recovery Codes
296312^^^^^^^^^^^^^^^
0 commit comments