Auth0 Integration with fastapi

I’m trying to integrate a fastapi python server with auth0.
Although while setting up I’m getting this particular error for this line of code

jsonurl = urlopen("https://" + AUTH0_DOMAIN + "/.well-known/jwks.json")

Error:

> File "./app/auth0.py", line 29, in get_current_user
>     jsonurl = urlopen("https://" + AUTH0_DOMAIN + "/.well-known/jwks.json")
>   File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 222, in urlopen
>     return opener.open(url, data, timeout)
>   File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 525, in open
>     response = self._open(req, data)
>   File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 542, in _open
>     result = self._call_chain(self.handle_open, protocol, protocol +
>   File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 502, in _call_chain
>     result = func(*args)
>   File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 1362, in https_open
>     return self.do_open(http.client.HTTPSConnection, req,
>   File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 1322, in do_open
>     raise URLError(err)
> urllib.error.URLError: <urlopen error [Errno 8] nodename nor servname provided, or not known>

Please help identify this error. Thank you.

Hey there,

Unfortunately we do not have any public guidance on integrating our Auth0 stack with FastAPI. I added some tags to your question so maybe someone from our community will be able to help.

Did you make sure that the AUTH0_DOMAIN constant is being replaced by the value of your Auth0 domain?

Rohan, did you manage to get this to work? I want to do the same thing and tried using https://pypi.org/project/fastapi-cloudauth/ but having a hard time. Is your code on github? Studying it alongside the fastapi-cloudauth may help me connect the dots. Thanks in advance!

1 Like

Tagging @rohan1 so maybe he’ll be notified and will get back to it.

Hi @jbebic - I just got it working with that Python package, by fetching data from a FastAPI endpoint hosted on Heroku, with a Next.js app hosted on Vercel.

For me, the part that was missing from the PyPi page was the detail about adding scope to the API in the Auth0 Dashboard (had me running in circles for longer than I’d like to admit). Have you already added permissions there?

If not, it can be done by creating/navigating to your API (which is also shown as a machine to machine application in your list of applications), then clicking on your app name, going to Permissions, then adding the permission scope that you specified as per the PyPi docs, as well as a description.

Lmk if this isn’t it! Happy to look into it!

1 Like

Thanks for sharing it with the rest of community!

1 Like