flexmeasures.auth.event_logging

Log authentication events: logins (succeeded and failed), two-factor failures, logouts and token requests.

Each line starts with “Authentication event:”, says what happened and to which user (by id), and gives the client’s IP address as the app sees it (behind a reverse proxy, that is the proxy’s, unless the proxy’s forwarded headers are applied). Passwords, codes and tokens are never logged. An email address that matches no user is logged as a short hash, so that repeated attempts on one address can be told apart without writing the guessed addresses to the log.

Functions

flexmeasures.auth.event_logging.email_fingerprint(email: str) → str

A short, stable hash of an email address, for log lines about addresses that match no user.

flexmeasures.auth.event_logging.log_authentication_event(message: str, failed: bool = False)
flexmeasures.auth.event_logging.log_failed_authentication(sender, user=None, auth_type=None, tfa=False, **kwargs)

Connected to Flask-Security’s user_failed_authn signal, which is sent for a known user’s wrong password or code.

flexmeasures.auth.event_logging.log_logout(sender, user=None, **kwargs)

Connected to Flask-Login’s user_logged_out signal.

flexmeasures.auth.event_logging.log_successful_login(sender, user=None, authn_via=None, **kwargs)

Connected to Flask-Security’s user_authenticated signal.

flexmeasures.auth.event_logging.register_at(app: Flask)