mirror of
https://github.com/fastapi-users/fastapi-users.git
synced 2025-08-15 11:11:16 +08:00
38 lines
992 B
Python
38 lines
992 B
Python
from fastapi import Depends, FastAPI
|
|
|
|
from app.models import UserDB
|
|
from app.users import (
|
|
auth_backend,
|
|
current_active_user,
|
|
fastapi_users,
|
|
google_oauth_client,
|
|
)
|
|
|
|
app = FastAPI()
|
|
|
|
app.include_router(
|
|
fastapi_users.get_auth_router(auth_backend), prefix="/auth/jwt", tags=["auth"]
|
|
)
|
|
app.include_router(fastapi_users.get_register_router(), prefix="/auth", tags=["auth"])
|
|
app.include_router(
|
|
fastapi_users.get_reset_password_router(),
|
|
prefix="/auth",
|
|
tags=["auth"],
|
|
)
|
|
app.include_router(
|
|
fastapi_users.get_verify_router(),
|
|
prefix="/auth",
|
|
tags=["auth"],
|
|
)
|
|
app.include_router(fastapi_users.get_users_router(), prefix="/users", tags=["users"])
|
|
app.include_router(
|
|
fastapi_users.get_oauth_router(google_oauth_client, auth_backend, "SECRET"),
|
|
prefix="/auth/google",
|
|
tags=["auth"],
|
|
)
|
|
|
|
|
|
@app.get("/authenticated-route")
|
|
async def authenticated_route(user: UserDB = Depends(current_active_user)):
|
|
return {"message": f"Hello {user.email}!"}
|