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/7ffd7e76226c3a602b935bc187bdca45 to your computer and use it in GitHub Desktop.
Save francbartoli/7ffd7e76226c3a602b935bc187bdca45 to your computer and use it in GitHub Desktop.
@app.get("/")
async def homepage():
return "Welcome to the security test!"
@app.get("/openapi.json", tags=["documentation"])
async def get_open_api_endpoint(api_key: APIKey = Depends(get_api_key)):
response = JSONResponse(
get_openapi(title="FastAPI security test", version=1, routes=app.routes)
)
return response
@app.get("/documentation", tags=["documentation"])
async def get_documentation(api_key: APIKey = Depends(get_api_key)):
response = get_swagger_ui_html(openapi_url="/openapi.json", title="docs")
response.set_cookie(
API_KEY_NAME,
value=api_key,
domain=COOKIE_DOMAIN,
httponly=True,
max_age=1800,
expires=1800,
)
return response
@app.get("/logout")
async def route_logout_and_remove_cookie():
response = RedirectResponse(url="/")
response.delete_cookie(API_KEY_NAME, domain=COOKIE_DOMAIN)
return response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment