mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
28 lines
877 B
Python
28 lines
877 B
Python
from fastapi import APIRouter, HTTPException, status, Depends
|
|
from jose import jwt
|
|
import datetime
|
|
from app.config import get_settings
|
|
|
|
router = APIRouter(
|
|
prefix="/local",
|
|
tags=["local"],
|
|
)
|
|
|
|
|
|
def create_dummy_token(secret: str, algorithm: str):
|
|
data = {
|
|
"sub": "known_id",
|
|
"name": "Test User",
|
|
"iat": datetime.datetime.utcnow(),
|
|
"exp": datetime.datetime.utcnow() + datetime.timedelta(minutes=30)
|
|
}
|
|
return jwt.encode(data, secret, algorithm=algorithm)
|
|
|
|
|
|
@router.get("/dummy-token")
|
|
async def dummy_token():
|
|
settings = get_settings()
|
|
if settings.ENVIRONMENT != "local":
|
|
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN,
|
|
detail="Dummy token can only be generated in local environment")
|
|
return {"dummy_token": create_dummy_token(settings.SECRET_KEY, settings.ALGORITHM)}
|