How to use fastapi-users with google oauth (from official docs full example)

374 Views Asked by At

I've copied the full sqlalchemy example from the fastapi-users docs with postgresql+asyncpg and I have something working, but I'm not sure if I'm using it correctly with Google.

In the swagger UI I am able to use the Authorize form successfully and I can see fastapi reports "POST /auth/jwt/login HTTP/1.1" 200 OK.

I am trying to understand the order of endpoints being used in this authorization process. So in parallel I am using the swagger UI to execute the following steps:

  1. Post to /auth/jwt/login. This returns {"access_token": <some_token>, "token_type": "bearer"}.
  2. Post to /auth/request-verify-token and although in swagger the response body is null, the fastapi logs show Verification requested for user 8d1c6256-c988-446d-b726-77ba934ceb5b. Verification token: <some_token> followed by "POST /auth/request-verify-token HTTP/1.1" 202 Accepted.
  3. Post to /auth/verify with the token from step 2, which returns "POST /auth/verify HTTP/1.1" 200 OK and the user info.

Is this the correct order of events? At what point does google come into play? I do not see any google endpoints being hit (/auth/google/authorize and /auth/google/callback). If I want to use google, do I need to modify the prefix in get_auth_router() or do I need to modify the full example in any way?

app.include_router(
    fastapi_users.get_auth_router(auth_backend), prefix="/auth/jwt", tags=["auth"]
)

Also, why are there 2 tables in the DB (user and oauth_account). I can see my google user in user but the oauth_account table is empty. Should both tables have been filled out?

0

There are 0 best solutions below