🚚 Move hmac_hash() to ohmyapi_auth.utils

This commit is contained in:
Brian Wiborg 2025-10-22 11:55:47 +02:00
parent 58f1387aaf
commit 10681cc15b
No known key found for this signature in database
2 changed files with 18 additions and 10 deletions

View file

@ -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):

View file

@ -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")