diff --git a/swh/auth/django/utils.py b/swh/auth/django/utils.py index 1db47092c62f0db1ff30d3ee93b84a66eb8840f6..78b5a1c074d679bf6e4cbe779213d82d4961f4af 100644 --- a/swh/auth/django/utils.py +++ b/swh/auth/django/utils.py @@ -5,6 +5,7 @@ from datetime import datetime, timedelta from typing import Any, Dict, Optional +from uuid import UUID from django.conf import settings from django.contrib.auth.models import Group @@ -25,7 +26,7 @@ def keycloak_uuid_to_django_id(keycloak_uuid: str) -> int: Django integer identifier for the user """ - return int("".join(keycloak_uuid.split("-")), 16) + return UUID(keycloak_uuid).int def django_id_to_keycloak_uuid(django_id: int) -> str: @@ -37,16 +38,7 @@ def django_id_to_keycloak_uuid(django_id: int) -> str: Returns: Keycloak UUID identifier for the user """ - django_hex_id = hex(django_id)[2:] - return "-".join( - [ - django_hex_id[:8], - django_hex_id[8:12], - django_hex_id[12:16], - django_hex_id[16:20], - django_hex_id[20:], - ] - ) + return str(UUID(int=django_id)) def oidc_user_from_decoded_token(