fastapi_tools.routers.auth
¶
Authentication router for Google OAuth endpoints.
Functions:
-
auth_status–Check if user is authenticated.
-
get_auth_service–Get auth service from app state.
-
get_current_user_info–Get current authenticated user information.
-
google_callback–Handle Google OAuth callback.
-
google_login–Initiate Google OAuth login flow.
-
logout–Logout current user.
auth_status
async
¶
Check if user is authenticated.
Source code in src/fastapi_tools/routers/auth.py
get_auth_service
¶
get_current_user_info
async
¶
get_current_user_info(
session: Annotated[
SessionData, Depends(get_current_user)
],
) -> UserResponse
Get current authenticated user information.
Source code in src/fastapi_tools/routers/auth.py
google_callback
async
¶
google_callback(
request: Request,
auth_service: Annotated[
GoogleAuthService, Depends(get_auth_service)
],
code: Annotated[
str,
Query(description="Authorization code from Google"),
],
state: Annotated[
str,
Query(
description="State parameter for CSRF protection"
),
],
error: Annotated[
str | None,
Query(description="Error from Google OAuth"),
] = None,
) -> RedirectResponse
Handle Google OAuth callback.
Source code in src/fastapi_tools/routers/auth.py
google_login
async
¶
google_login(
request: Request,
auth_service: Annotated[
GoogleAuthService, Depends(get_auth_service)
],
*,
redirect: Annotated[
bool,
Query(
description="Redirect to Google if true, else return URL."
),
] = True,
) -> AuthURLResponse | RedirectResponse
Initiate Google OAuth login flow.
Source code in src/fastapi_tools/routers/auth.py
logout
async
¶
logout(
request: Request,
session: Annotated[
SessionData, Depends(get_current_user)
],
auth_service: Annotated[
GoogleAuthService, Depends(get_auth_service)
],
) -> LogoutResponse | RedirectResponse
Logout current user.
For browser requests returns a redirect to landing page. For HTMX requests returns an HX-Redirect header. For API requests returns JSON.