mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2024-08-19 23:23:00 +00:00
Co-authored-by: def <dettlaff@riseup.net> Co-authored-by: Inex Code <inex.code@selfprivacy.org> Reviewed-on: https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api/pulls/18 Co-authored-by: def <dettlaff@riseup.net> Co-committed-by: def <dettlaff@riseup.net>
34 lines
733 B
Python
34 lines
733 B
Python
"""
|
|
Model of the access token.
|
|
|
|
Access token has a token string, device name and date of creation.
|
|
"""
|
|
from datetime import datetime
|
|
import secrets
|
|
from pydantic import BaseModel
|
|
|
|
|
|
class Token(BaseModel):
|
|
"""
|
|
Model of the access token.
|
|
|
|
Access token has a token string, device name and date of creation.
|
|
"""
|
|
|
|
token: str
|
|
device_name: str
|
|
created_at: datetime
|
|
|
|
@staticmethod
|
|
def generate(device_name: str) -> "Token":
|
|
"""
|
|
Factory to generate a random token.
|
|
"""
|
|
creation_date = datetime.now()
|
|
token = secrets.token_urlsafe(32)
|
|
return Token(
|
|
token=token,
|
|
device_name=device_name,
|
|
created_at=creation_date,
|
|
)
|