An end-point to render the authentication view. It supports two HTTP methods: 1. GET : Generate the view listing all the supported auth methods. 2. POST: Validate the code/OTP, or whatever data the selected auth method supports. Returns: Response: Redirect
()
| 90 | @pgCSRFProtect.exempt |
| 91 | @login_required |
| 92 | def validate_view() -> Response: |
| 93 | """ |
| 94 | An end-point to render the authentication view. |
| 95 | |
| 96 | It supports two HTTP methods: |
| 97 | 1. GET : Generate the view listing all the supported auth methods. |
| 98 | 2. POST: Validate the code/OTP, or whatever data the selected auth method |
| 99 | supports. |
| 100 | |
| 101 | Returns: |
| 102 | Response: Redirect to 'next' url in case authentication validate, |
| 103 | otherwise - a view with listing down all the supported auth |
| 104 | methods, and it's supporting views. |
| 105 | """ |
| 106 | |
| 107 | # Load at runtime to avoid circular dependency |
| 108 | from pgadmin.authenticate import get_logout_url |
| 109 | |
| 110 | next_url = request.args.get("next", None) |
| 111 | |
| 112 | if next_url is None or next_url == url_for('mfa.register') or \ |
| 113 | next_url == url_for('mfa.validate') or \ |
| 114 | not _is_safe_redirect_url(next_url): |
| 115 | next_url = url_for(_INDEX_URL) |
| 116 | |
| 117 | if session.get('mfa_authenticated', False) is True: |
| 118 | return redirect(next_url) |
| 119 | |
| 120 | return_code = 200 |
| 121 | mfa_method = None |
| 122 | user_mfa_auths = user_supported_mfa_methods() |
| 123 | |
| 124 | if request.method == 'POST': |
| 125 | try: |
| 126 | form_data = {key: request.form[key] for key in request.form} |
| 127 | next_url = form_data.pop('next', None) |
| 128 | if not _is_safe_redirect_url(next_url): |
| 129 | next_url = url_for(_INDEX_URL) |
| 130 | mfa_method = form_data.pop('mfa_method', None) |
| 131 | |
| 132 | __handle_mfa_validation_request( |
| 133 | mfa_method, user_mfa_auths, form_data |
| 134 | ) |
| 135 | |
| 136 | session['mfa_authenticated'] = True |
| 137 | |
| 138 | return redirect(next_url) |
| 139 | |
| 140 | except ValidationException as ve: |
| 141 | current_app.logger.warning(( |
| 142 | "MFA validation failed for the user '{}' with an error: " |
| 143 | "{}" |
| 144 | ).format(current_user.username, str(ve))) |
| 145 | flash(str(ve), MessageType.ERROR) |
| 146 | return_code = 401 |
| 147 | except Exception as ex: |
| 148 | current_app.logger.exception(ex) |
| 149 | flash(str(ex), MessageType.ERROR) |
nothing calls this directly
no test coverage detected