A utility funtion to add/update the auth method in the configuration database for the current user with the method specific options. e.g. email-address for 'email' method, and 'secret' for the 'authenticator' Args: auth_name (str): Name of the auth method options (
(auth_name: str, options: str)
| 357 | |
| 358 | |
| 359 | def mfa_add(auth_name: str, options: str) -> None: |
| 360 | """ |
| 361 | A utility funtion to add/update the auth method in the configuration |
| 362 | database for the current user with the method specific options. |
| 363 | |
| 364 | e.g. email-address for 'email' method, and 'secret' for the 'authenticator' |
| 365 | |
| 366 | Args: |
| 367 | auth_name (str): Name of the auth method |
| 368 | options (str) : A data options specific to the auth method |
| 369 | """ |
| 370 | auth = UserMFA.query.filter_by( |
| 371 | user_id=current_user.id, mfa_auth=auth_name |
| 372 | ).first() |
| 373 | |
| 374 | if auth is None: |
| 375 | auth = UserMFA( |
| 376 | user_id=current_user.id, |
| 377 | mfa_auth=auth_name, |
| 378 | options=options |
| 379 | ) |
| 380 | db.session.add(auth) |
| 381 | |
| 382 | # We will override the existing options |
| 383 | auth.options = options |
| 384 | |
| 385 | db.session.commit() |
| 386 | |
| 387 | |
| 388 | def fetch_auth_option(auth_name: str) -> (str, bool): |
no test coverage detected