From 10681cc15b9c415e922214a3c87002678ce199ed Mon Sep 17 00:00:00 2001 From: Brian Wiborg Date: Wed, 22 Oct 2025 11:55:47 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=9A=20Move=20hmac=5Fhash()=20to=20ohmy?= =?UTF-8?q?api=5Fauth.utils?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ohmyapi/builtin/auth/models.py | 11 +---------- src/ohmyapi/builtin/auth/utils.py | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 10 deletions(-) create mode 100644 src/ohmyapi/builtin/auth/utils.py diff --git a/src/ohmyapi/builtin/auth/models.py b/src/ohmyapi/builtin/auth/models.py index d4c2f12..e8894c1 100644 --- a/src/ohmyapi/builtin/auth/models.py +++ b/src/ohmyapi/builtin/auth/models.py @@ -1,6 +1,3 @@ -import hmac -import hashlib -import base64 from functools import wraps from secrets import token_bytes from typing import List, Optional @@ -12,15 +9,9 @@ from tortoise.contrib.pydantic import pydantic_queryset_creator from ohmyapi.db import Model, field, Q from ohmyapi.router import HTTPException -import settings +from .utils import hmac_hash pwd_context = CryptContext(schemes=["argon2"], deprecated="auto") -SECRET_KEY = getattr(settings, "SECRET_KEY", "OhMyAPI Secret Key") - - -def hmac_hash(data: str) -> str: - digest = hmac.new(SECRET_KEY.encode("UTF-8"), data.encode("utf-8"), hashlib.sha256).digest() - return base64.urlsafe_b64encode(digest).decode("utf-8") class Group(Model): diff --git a/src/ohmyapi/builtin/auth/utils.py b/src/ohmyapi/builtin/auth/utils.py new file mode 100644 index 0000000..e54a5da --- /dev/null +++ b/src/ohmyapi/builtin/auth/utils.py @@ -0,0 +1,17 @@ +import base64 +import hashlib +import hmac + +import settings + +SECRET_KEY = getattr(settings, "SECRET_KEY", "OhMyAPI Secret Key") + + +def hmac_hash(data: str) -> str: + digest = hmac.new( + SECRET_KEY.encode("UTF-8"), + data.encode("utf-8"), + hashlib.sha256, + ).digest() + return base64.urlsafe_b64encode(digest).decode("utf-8") +