Random 401 response with "invalid_header: unable to find appropriate key" when calling python flask API

Hi,
I have been struggling a lot with Auth0 with random 401 response when calling either auth0 apis or my own python flask API. This has been lasting for a long time.

My environment:
Nodejs 16, Nextjs 12.1.4, Nextjs-auth0 1.7.0
Authenticate using SSR Nextjs paradigm
Docker, Azure web app service
Cloudflare as my DNS provider

Auth0 webapp settinig:
Regular Web Application

In the same endpoint calls, the endpoint calls fail from time to time:



The response in python is:
invalid_header: unable to find appropriate key


The accesstoken sometimes does not have the right RSA key (kid missing).

This happens to almost all endpoints, including other examples provided by auth0 sdk example:
/api/auth/me
/api/auth/profile
The weird thing is that in my development deployment, this does not happen

Does anyone know what’s going on with this?

Hi @chu,

Welcome to the Auth0 Community!

I understand that you have encountered intermittent errors when authenticating against your APIs.

First, could you please decode the access token from the response using jwt.io to see if the access token has a valid signature?

And could you please clarify which Auth0 SDKs did you test that you found the same issue with almost all endpoints?

I would like to see if I can reproduce this issue.

Thank you.

Thanks for reply. Will come back shortly with data.

1 Like

Hi @rueben.tiow ,

The access tokens are identical for both failing and ok API calls and the signature is verified using jwt.io. auth0-python==3.13.0 is SDK used in Flask. It is happening in almost all endpoints from my side and I do not see a clear pattern when it shall happen.

Hi @chu,

Thank you for your response.

In this case, could you please capture a HAR file of the authentication events, including the Invalid_header error and DM it to me?

I would like to investigate your observations further.

Thank you.

By adding a proper scope, the problem disappeared even though I am not using the scope. Thanks for the help from @rueben.tiow

2 Likes