Advertisement
Guest User

Untitled

a guest
May 21st, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. @app.get("/")
  2. async def homepage():
  3. return "Welcome to the security test!"
  4.  
  5.  
  6. @app.get(f"{ERROR_ROUTE}", tags=["security"])
  7. async def login_error():
  8. return "Something went wrong logging in!"
  9.  
  10.  
  11. @app.get("/logout", tags=["security"])
  12. async def route_logout_and_remove_cookie():
  13. response = RedirectResponse(url="/")
  14. response.delete_cookie(COOKIE_AUTHORIZATION_NAME, domain=COOKIE_DOMAIN)
  15. return response
  16.  
  17.  
  18. @app.get("/openapi.json", tags=["documentation"])
  19. async def get_open_api_endpoint(current_user: User = Depends(get_current_active_user)):
  20. response = JSONResponse(
  21. get_openapi(title="FastAPI security test", version=1, routes=app.routes)
  22. )
  23. return response
  24.  
  25.  
  26. @app.get("/documentation", tags=["documentation"])
  27. async def get_documentation(current_user: User = Depends(get_current_active_user)):
  28. response = get_swagger_ui_html(openapi_url="/openapi.json", title="docs")
  29. return response
  30.  
  31.  
  32. @app.get("/secure_endpoint", tags=["security"])
  33. async def get_open_api_endpoint(current_user: User = Depends(get_current_active_user)):
  34. response = "How cool is this?"
  35. return response
  36.  
  37.  
  38. @app.get("/users/me/", response_model=User, tags=["users"])
  39. async def read_users_me(current_user: User = Depends(get_current_active_user)):
  40. return current_user
  41.  
  42.  
  43. @app.get("/users/me/items/", tags=["users"])
  44. async def read_own_items(current_user: User = Depends(get_current_active_user)):
  45. return [{"item_id": "Foo", "owner": current_user.username}]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement