Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @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}]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement