core: add User.uid for globally unique user ID

This commit is contained in:
Jens Langhammer
2021-02-14 18:25:50 +01:00
parent d122bddae2
commit 60c244c31d
4 changed files with 11 additions and 14 deletions

View File

@ -1,8 +1,10 @@
"""authentik core models"""
from datetime import timedelta
from hashlib import sha256
from typing import Any, Dict, Optional, Type
from uuid import uuid4
from django.conf import settings
from django.contrib.auth.models import AbstractUser
from django.contrib.auth.models import UserManager as DjangoUserManager
from django.db import models
@ -119,6 +121,11 @@ class User(GuardianUserMixin, AbstractUser):
self.password_change_date = now()
return super().set_password(password)
@property
def uid(self) -> str:
"""Generate a globall unique UID, based on the user ID and the hashed secret key"""
return sha256(f"{self.id}-{settings.SECRET_KEY}".encode("ascii")).hexdigest()
class Meta:
permissions = (