swh.auth.django.utils module#

swh.auth.django.utils.oidc_user_from_decoded_token(decoded_token: Dict[str, Any], client_id: Optional[str] = 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: Optional[Dict[str, Any]] = None, query_params: Optional[Dict[str, Any]] = None, current_app: Optional[str] = None, urlconf: Optional[str] = None, request: Optional[HttpRequest] = 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