Skip to content

Instantly share code, notes, and snippets.

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 francbartoli/472fda911fbe16670834e50e998ea3f2 to your computer and use it in GitHub Desktop.
Save francbartoli/472fda911fbe16670834e50e998ea3f2 to your computer and use it in GitHub Desktop.
@app.get("/")
async def homepage():
return "Welcome to the security test!"
@app.get(f"{ERROR_ROUTE}", tags=["security"])
async def login_error():
return "Something went wrong logging in!"
@app.get("/logout", tags=["security"])
async def route_logout_and_remove_cookie():
response = RedirectResponse(url="/")
response.delete_cookie(COOKIE_AUTHORIZATION_NAME, domain=COOKIE_DOMAIN)
return response
@app.get("/openapi.json", tags=["documentation"])
async def get_open_api_endpoint(current_user: User = Depends(get_current_active_user)):
response = JSONResponse(
get_openapi(title="FastAPI security test", version=1, routes=app.routes)
)
return response
@app.get("/documentation", tags=["documentation"])
async def get_documentation(current_user: User = Depends(get_current_active_user)):
response = get_swagger_ui_html(openapi_url="/openapi.json", title="docs")
return response
@app.get("/secure_endpoint", tags=["security"])
async def get_open_api_endpoint(current_user: User = Depends(get_current_active_user)):
response = "How cool is this?"
return response
@app.get("/users/me/", response_model=User, tags=["users"])
async def read_users_me(current_user: User = Depends(get_current_active_user)):
return current_user
@app.get("/users/me/items/", tags=["users"])
async def read_own_items(current_user: User = Depends(get_current_active_user)):
return [{"item_id": "Foo", "owner": current_user.username}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment