🚚 Move hmac_hash() to ohmyapi_auth.utils
This commit is contained in:
parent
58f1387aaf
commit
10681cc15b
2 changed files with 18 additions and 10 deletions
|
|
@ -1,6 +1,3 @@
|
||||||
import hmac
|
|
||||||
import hashlib
|
|
||||||
import base64
|
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
from secrets import token_bytes
|
from secrets import token_bytes
|
||||||
from typing import List, Optional
|
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.db import Model, field, Q
|
||||||
from ohmyapi.router import HTTPException
|
from ohmyapi.router import HTTPException
|
||||||
|
|
||||||
import settings
|
from .utils import hmac_hash
|
||||||
|
|
||||||
pwd_context = CryptContext(schemes=["argon2"], deprecated="auto")
|
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):
|
class Group(Model):
|
||||||
|
|
|
||||||
17
src/ohmyapi/builtin/auth/utils.py
Normal file
17
src/ohmyapi/builtin/auth/utils.py
Normal 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")
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue