Created
May 18, 2023 17:32
-
-
Save artemonsh/aaf145b53d0da4b12fc6d909f97e30a1 to your computer and use it in GitHub Desktop.
FastAPI добавление замков на эндпоинты
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from fastapi import Depends, FastAPI | |
from fastapi.security import OAuth2PasswordBearer | |
app = FastAPI() | |
oauth2_scheme = OAuth2PasswordBearer( | |
tokenUrl="api/v1/auth/login", | |
) | |
@app.get("/protected", dependencies=[Depends(oauth2_scheme)]) | |
async def get_protected(): | |
return 1 | |
@app.get("/unprotected") | |
async def get_unprotected(): | |
return 2 |
Author
artemonsh
commented
May 18, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment