Skip to content

Instantly share code, notes, and snippets.

@artemonsh
Created May 18, 2023 17:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save artemonsh/aaf145b53d0da4b12fc6d909f97e30a1 to your computer and use it in GitHub Desktop.
Save artemonsh/aaf145b53d0da4b12fc6d909f97e30a1 to your computer and use it in GitHub Desktop.
FastAPI добавление замков на эндпоинты
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
@artemonsh
Copy link
Author

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment