I’m trying to use oauth2 (Google) with fastapi-users.
I’m following the official tutorial with Beanie.
You can find the whole code here: https://github.com/fastapi-users/fastapi-users/tree/master/examples/beanie-oauth
When I test I successufly can login, i also see the logs that the user is registered and there is also the user created in the DB. But when i try to access to a protected route i get 401 Unauthorized.
These are the steps that I’m doing:
-
Start the app and call the authorize with Google http://127.0.0.1:8000/auth/google/authorize
-
The Google login page opens and I log in with my account (the same one I allowed on the Google console). From the MongoDB database I can see that a user is created with the correct email etc.
-
I receive an access token. Example:
{ "access_token":"eyJhbGhiOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI2NjYxYmZjOTdlZjNiZjIxMmQzYzRlZTUiLCJhdWQiOlsiZmFzdGFwaS11c2VyczphdXRoIl0sImV4cCI6MTcxNzY4NTk1MH0.oIJYCnGcqEM7Gv0hsfp9qXYQ5W9v0EKX6PvU8-MJ7hg", "token_type": "bearer" }
-
I make a request to the protected route http://127.0.0.1:8000/authenticated-route adding the Authorization header with the access token value received before (“Bearer eyJhbGhiOiJIU…”)
-
The response is 401 Unauthorized.
What am I doing wrong? I think I’m missing some pieces.
user8724769 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.