Forked from nilsdebruin/fastapi_google_authentication_endpoints.py
Created
June 2, 2019 12:39
-
-
Save francbartoli/472fda911fbe16670834e50e998ea3f2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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