fooder-api/fooder/view/token.py

27 lines
742 B
Python
Raw Normal View History

2023-04-01 16:19:12 +02:00
from fastapi import APIRouter, Depends, Request
2023-04-02 14:38:22 +02:00
from ..model.token import Token, RefreshTokenPayload
from ..controller.token import CreateToken, RefreshToken
2023-04-01 16:19:12 +02:00
from fastapi.security import OAuth2PasswordRequestForm
from typing import Annotated
router = APIRouter(tags=["token"])
2023-04-01 20:23:04 +02:00
@router.post("", response_model=Token)
2023-04-01 16:19:12 +02:00
async def create_token(
request: Request,
data: Annotated[OAuth2PasswordRequestForm, Depends()],
controller: CreateToken = Depends(CreateToken),
):
return await controller.call(data)
2023-04-02 14:38:22 +02:00
@router.post("/refresh", response_model=Token)
async def refresh_token(
request: Request,
data: RefreshTokenPayload,
controller: RefreshToken = Depends(RefreshToken),
):
return await controller.call(data)