secret generation on startup
This commit is contained in:
parent
f56c2fb19b
commit
b38216a223
1 changed files with 10 additions and 1 deletions
|
@ -4,11 +4,12 @@ import functools
|
||||||
import json
|
import json
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
|
from secrets import token_hex
|
||||||
|
|
||||||
from jose import JWTError, jwt
|
from jose import JWTError, jwt
|
||||||
from jose.constants import ALGORITHMS
|
from jose.constants import ALGORITHMS
|
||||||
from passlib.context import CryptContext
|
from passlib.context import CryptContext
|
||||||
from pydantic import BaseModel, BaseSettings, Field
|
from pydantic import BaseModel, BaseSettings, Field, validator
|
||||||
from sqlalchemy import create_engine
|
from sqlalchemy import create_engine
|
||||||
from sqlalchemy.engine import Engine
|
from sqlalchemy.engine import Engine
|
||||||
|
|
||||||
|
@ -70,6 +71,14 @@ class JWTConfig(BaseModel):
|
||||||
hash_algorithm: str = ALGORITHMS.HS256
|
hash_algorithm: str = ALGORITHMS.HS256
|
||||||
expiry_minutes: int = 30
|
expiry_minutes: int = 30
|
||||||
|
|
||||||
|
@validator("secret")
|
||||||
|
@classmethod
|
||||||
|
def ensure_secret(cls, value: str | None) -> str:
|
||||||
|
if value is None:
|
||||||
|
return token_hex(32)
|
||||||
|
|
||||||
|
return value
|
||||||
|
|
||||||
async def create_token(
|
async def create_token(
|
||||||
self,
|
self,
|
||||||
username: str,
|
username: str,
|
||||||
|
|
Loading…
Reference in a new issue