OAuth2
To configure OAuth client, we need install oauth support.
pip install 'fastapi-fastauth[oauth]'
After that we need create OAuth model and OAuthRepository. Then create BaseAuthManager and init FastAuth.
OAuth Client
OAuth2 router required BaseOAuth client, we need choose provider and init it client. For example, let's choose github
provider and create client
from httpx_oauth.clients.github import GitHubOAuth2
github_client = GitHubOAuth2("CLIENT_ID", "CLIENT_SECRET_KEY")
After that we can pass it to router
OAuth router
To get oauth router you need to setup OAuth client, and pass it to router. If you also have RBAC support, you need to set True
in default_role
, or role codename if you don`t want to use FastAuthConfig.USER_DEFAULT_ROLE
from .oauth import github_client
app.include_router(
auth_router.get_oauth_router(github_client, default_role=True),
tags=["OAuth"]
)