tokusumi / fastapi-cloudauth

Simple integration between FastAPI and cloud authentication services (AWS Cognito, Auth0, Firebase Authentication).
MIT License
323 stars 35 forks source link

Auth0: get_current_user always gives 401 #50

Closed lesiki closed 2 years ago

lesiki commented 2 years ago

Hi there,

This is almost certainly user error & not a bug, as I'm new to Auth0.

In Auth0, I have configured an application (which is a VueJS client) set up as well as an API (my FastAPI back-end).

I've managed to get authentication working using the example def main_endpoint_test(current_user: AccessUser = Depends(auth.claim(AccessUser))) - when I do this, I can get the user_id/sub, but I don't get the user email.

I tried using the other approach shown in the example: def secure_user(current_user: Auth0Claims = Depends(get_current_user)):. When I use this, I always get a 401 response. I have initialised the get_current_user passing in the domain and client_id as shown in the example - because the domain is working fine in the simpler auth method, maybe my mistake is entering the wrong value for the client_id?

What is the client ID value should I be setting here, is it my Auth0 Application's client ID (i.e. the one for the VueJS client)? Is it the custom API's ID (as far as I can tell, there is no field explicitly labelled "client ID" in auth0's APIs)?

lesiki commented 2 years ago

Alternatively, is there any way to add more verbose logging so that I can try to narrow this down?

lesiki commented 2 years ago

I figured out how to add the email to the token using Auth0 rules, as described here: https://github.com/tokusumi/fastapi-cloudauth/issues/4#issuecomment-698318481