mdvtools.auth.authutils#

Attributes#

Functions#

create_auth_provider(auth_method, app)

Factory function to create an authentication provider.

get_auth_provider()

Determines the correct authentication method and returns an instance of the

is_authenticated()

Validate the current user via Auth0 or Shibboleth.

register_before_request_auth(app)

Attach the before_request auth logic to the Flask app.

needs_cache_refresh()

Check if cache needs to be refreshed based on time interval.

cache_user_projects()

Caches user details and their associated project permissions in memory.

update_cache([user_id, project_id, user_data, ...])

Updates the in-memory caches (user_cache, user_project_cache, all_users_cache, active_projects_cache)

Module Contents#

mdvtools.auth.authutils.logger[source]#
mdvtools.auth.authutils.user_cache[source]#
mdvtools.auth.authutils.user_project_cache[source]#
mdvtools.auth.authutils.all_users_cache = [][source]#
mdvtools.auth.authutils.active_projects_cache = [][source]#
mdvtools.auth.authutils.cache_last_updated = None[source]#
mdvtools.auth.authutils.CACHE_REFRESH_INTERVAL = 300[source]#
mdvtools.auth.authutils.create_auth_provider(auth_method: str, app)[source]#

Factory function to create an authentication provider.

mdvtools.auth.authutils.get_auth_provider()[source]#

Determines the correct authentication method and returns an instance of the corresponding auth provider.

The resolution order is: 1. If DEFAULT_AUTH_METHOD in the app config is explicitly set to ‘dummy’,

the DummyAuthProvider is ALWAYS used. This is a developer override for safe local testing.

  1. If ‘auth_method’ is present in the session, that method is used.

  2. Otherwise, the value from the required DEFAULT_AUTH_METHOD app configuration is used.

Raises:

ValueError – If DEFAULT_AUTH_METHOD is not configured in the application.

mdvtools.auth.authutils.is_authenticated()[source]#

Validate the current user via Auth0 or Shibboleth.

mdvtools.auth.authutils.register_before_request_auth(app)[source]#

Attach the before_request auth logic to the Flask app.

mdvtools.auth.authutils.needs_cache_refresh()[source]#

Check if cache needs to be refreshed based on time interval.

mdvtools.auth.authutils.cache_user_projects()[source]#

Caches user details and their associated project permissions in memory.

mdvtools.auth.authutils.update_cache(user_id=None, project_id=None, user_data=None, project_data=None, permissions=None)[source]#

Updates the in-memory caches (user_cache, user_project_cache, all_users_cache, active_projects_cache) for the provided user and project details, including any changes in permissions.

Parameters:
  • user_id – The ID of the user whose cache needs to be updated.

  • project_id – The ID of the project to be added or updated in the cache.

  • user_data – A dictionary containing the user’s details (if updating the user cache).

  • project_data – A dictionary containing the project’s details (if updating the project cache).

  • permissions – A dictionary containing the user’s permissions for a project (optional).