swh.auth.django.utils module#

swh.auth.django.utils.keycloak_uuid_to_django_id(keycloak_uuid: str) int[source]#

Convert keycloak user uuid to its django integer id.

Parameters:

keycloak_uuid – UUID identifier of a Keycloak user

Returns:

Django integer identifier for the user

swh.auth.django.utils.django_id_to_keycloak_uuid(django_id: int) str[source]#

Convert django user integer id to its keycloak uuid.

Parameters:

django_id – Integer identifier of a django user

Returns:

Keycloak UUID identifier for the user

swh.auth.django.utils.oidc_user_from_decoded_token(decoded_token: Dict[str, Any], client_id: str | None = None) OIDCUser[source]#

Create an OIDCUser out of a decoded token

Parameters:
  • decoded_token – Decoded token Dict

  • client_id – Optional client id of the keycloak client instance used to decode the token. If not provided, the permissions will be empty.

Returns:

The OIDCUser instance

swh.auth.django.utils.oidc_user_from_profile(oidc_client: KeycloakOpenIDConnect, oidc_profile: Dict[str, Any]) OIDCUser[source]#

Initialize an OIDCUser out of an oidc profile dict.

Parameters:
  • oidc_client – KeycloakOpenIDConnect used to discuss with keycloak

  • oidc_profile – OIDC profile retrieved once connected to keycloak

Returns:

OIDCUser instance parsed out of the token received.

swh.auth.django.utils.oidc_profile_cache_key(oidc_client: KeycloakOpenIDConnect, user_id: int) str[source]#
swh.auth.django.utils.keycloak_oidc_client() KeycloakOpenIDConnect[source]#

Instantiate a KeycloakOpenIDConnect class from the following django settings:

  • SWH_AUTH_SERVER_URL

  • SWH_AUTH_REALM_NAME

  • SWH_AUTH_CLIENT_ID

Returns:

An object to ease the interaction with the Keycloak server

Raises:

ValueError – at least one mandatory django setting is not set

swh.auth.django.utils.reverse(viewname: str, url_args: Dict[str, Any] | None = None, query_params: Dict[str, Any] | None = None, current_app: str | None = None, urlconf: str | None = None, request: HttpRequest | None = None) str[source]#

An override of django reverse function supporting query parameters.

Parameters:
  • viewname – the name of the django view from which to compute a url

  • url_args – dictionary of url arguments indexed by their names

  • query_params – dictionary of query parameters to append to the reversed url

  • current_app – the name of the django app tighten to the view

  • urlconf – url configuration module

  • request – build an absolute URI if provided

Returns:

the url of the requested view with processed arguments and query parameters

Return type:

str