Getting started¶
Installation¶
First of all, you need to install fastapi-allauth.
Minimum Example¶
Villain Fastapi Allauth
provides several ready-to-use clients.
Here is an example of google oauth to start with.
from fastapi import FastAPI
from fastapi import APIRouter
from fastapi_allauth.oauth import GoogleOauth
from fastapi_allauth import AllauthManager
from db import engine, SessionLocal
from models import CustomUser, Base
Base.metadata.create_all(bind=engine)
...
JWT_SECRET = 'your secret'
allauthManager = AllauthManager(db=get_db(),
user=CustomUser, secret=JWT_SECRET, lifetime_second=3600)
googleOauth = GoogleOauth(
provider="GOOGLE",
client_id="your client",
client_secret="your secret",
redirect_uri="http://localhost:8000/google/callback",
scope=["openid", "email", "profile"]
)
app.include_router(allauthManager.get_oauth_router(
googleOauth), prefix="/google", tags=["google"])