openedx.core.djangoapps.user_authn package#

Subpackages#

Submodules#

openedx.core.djangoapps.user_authn.apps module#

User Authentication Configuration

class openedx.core.djangoapps.user_authn.apps.UserAuthnConfig(app_name, app_module)#

Bases: AppConfig

Application Configuration for User Authentication.

name = 'openedx.core.djangoapps.user_authn'#
plugin_app = {'signals_config': {'lms.djangoapp': {'receivers': [{'receiver_func_name': 'user_fields_changed', 'signal_path': 'common.djangoapps.util.model_utils.USER_FIELDS_CHANGED'}]}}, 'url_config': {'lms.djangoapp': {'app_name': 'openedx.core.djangoapps.user_authn', 'namespace': '', 'regex': '', 'relative_path': 'urls'}}}#

openedx.core.djangoapps.user_authn.cookies module#

Utility functions for setting “logged in” cookies used by subdomains.

openedx.core.djangoapps.user_authn.cookies.are_logged_in_cookies_set(request)#

Check whether the request has logged in cookies set.

openedx.core.djangoapps.user_authn.cookies.delete_logged_in_cookies(response)#

Delete cookies indicating that the user is logged in (except for session cookie.) :param response: The response sent to the client. :type response: HttpResponse

Returns:

HttpResponse

openedx.core.djangoapps.user_authn.cookies.get_response_with_refreshed_jwt_cookies(request, user)#

Generates the response and resets the JWT related cookies in the response for the given user.

openedx.core.djangoapps.user_authn.cookies.set_logged_in_cookies(request, response, user)#

Set cookies at the time of user login. See ALL_LOGGED_IN_COOKIE_NAMES to see which cookies are set.

Parameters:
  • request (HttpRequest) – The request to the view, used to calculate the cookie’s expiration date based on the session expiration date.

  • response (HttpResponse) – The response on which the cookie will be set.

  • user (User) – The currently logged in user.

Returns:

HttpResponse

Returns the common cookie settings (e.g. expiration time).

openedx.core.djangoapps.user_authn.exceptions module#

User Authn related Exceptions.

exception openedx.core.djangoapps.user_authn.exceptions.AuthFailedError(value=None, redirect=None, redirect_url=None, error_code=None, context={})#

Bases: Exception

This is a helper for the login view, allowing the various sub-methods to error out with an appropriate failure message.

get_response()#

Returns a dict representation of the error.

exception openedx.core.djangoapps.user_authn.exceptions.VulnerablePasswordError(value, error_code, redirect_url=None)#

Bases: Exception

This is a helper for the login view, allowing the view to error out if password is vulnerable.

get_response()#

openedx.core.djangoapps.user_authn.message_types module#

ACE message types for user_authn-related emails.

class openedx.core.djangoapps.user_authn.message_types.PasswordReset(*args, **kwargs)#

Bases: BaseMessageType

A message to the user with password reset link.

class openedx.core.djangoapps.user_authn.message_types.PasswordResetSuccess(*args, **kwargs)#

Bases: BaseMessageType

A message to the user when the password rest was successful.

openedx.core.djangoapps.user_authn.serializers module#

MFE Context API Serializers

class openedx.core.djangoapps.user_authn.serializers.ContextDataSerializer(*args, **kwargs)#

Bases: Serializer

Context Data Serializers

get_pipelineUserDetails(obj)#
class openedx.core.djangoapps.user_authn.serializers.MFEContextSerializer(*args, **kwargs)#

Bases: Serializer

Serializer class to convert the keys of MFE Context Response dict object to camelCase format.

class openedx.core.djangoapps.user_authn.serializers.PipelineUserDetailsSerializer(*args, **kwargs)#

Bases: Serializer

Pipeline User Details Serializers

class openedx.core.djangoapps.user_authn.serializers.ProvidersSerializer(*args, **kwargs)#

Bases: Serializer

Providers Serializers

openedx.core.djangoapps.user_authn.signals module#

Signals for user_authn

openedx.core.djangoapps.user_authn.signals.user_fields_changed(user=None, table=None, changed_fields: Dict[str, Tuple[Any, Any]] | None = None, **_kwargs)#

Update a collection of user profile fields in segment when they change in the database

Parameters:
  • user – The user object for the user being changed

  • table – The name of the table being updated

  • changed_fields – A mapping from changed field name to old and new values.

openedx.core.djangoapps.user_authn.tasks module#

This file contains celery tasks for sending email

openedx.core.djangoapps.user_authn.toggles module#

Toggles for user_authn

openedx.core.djangoapps.user_authn.toggles.is_auto_generated_username_enabled()#

Checks if auto-generated username should be enabled.

openedx.core.djangoapps.user_authn.toggles.is_require_third_party_auth_enabled()#
openedx.core.djangoapps.user_authn.toggles.should_redirect_to_authn_microfrontend()#

Checks if login/registration should be done via MFE.

openedx.core.djangoapps.user_authn.urls module#

URLs for User Authentication

openedx.core.djangoapps.user_authn.urls_common module#

Common URLs for User Authentication

Note: The split between urls.py and urls_common.py is hopefully temporary. For now, this is needed because of difference in CMS and LMS that have not yet been cleaned up.

This is also home to urls for endpoints that have been consolidated from other djangoapps, which leads to inconsistent prefixing.

openedx.core.djangoapps.user_authn.utils module#

Utility functions used during user authentication.

openedx.core.djangoapps.user_authn.utils.check_pwned_password(password)#

Check the Pwned Databases for vulnerable passwords. check_pwned_password returns password hash suffix and a dictionary containing suffix of every SHA-1 password hash beginning with the specified prefix, followed by a count of how many times it appears in their data set.

openedx.core.djangoapps.user_authn.utils.generate_username_suggestions(name: str) list[str]#

Generate 3 available username suggestions based on the provided name.

Parameters:

name (str) – The full name to generate username suggestions from. Must contain only ASCII characters.

Returns:

A list of up to 3 available username suggestions,

or an empty list if name contains non-ASCII characters or if no valid suggestions could be generated.

Return type:

list[str]

Note

Generated usernames will be combinations of: - firstname + lastname - first initial + lastname - firstname + random number

openedx.core.djangoapps.user_authn.utils.is_registration_api_v1(request)#

Checks if registration api is v1 :param request: :return: Bool

openedx.core.djangoapps.user_authn.utils.is_safe_login_or_logout_redirect(redirect_to, request_host, dot_client_id, require_https)#

Determine if the given redirect URL/path is safe for redirection.

Parameters:
  • redirect_to (str) – The URL in question.

  • request_host (str) – Originating hostname of the request. This is always considered an acceptable redirect target.

  • dot_client_id (str|None) – ID of Django OAuth Toolkit client. It is acceptable to redirect to any of the DOT client’s redirect URIs. This argument is ignored if it is None.

  • require_https (str) – Whether HTTPs should be required in the redirect URL.

Returns: bool

openedx.core.djangoapps.user_authn.utils.remove_special_characters_from_name(name: str) str#

Module contents#