Intermittent 401 errors while testing my app

Hello, I have a working node app (deployed to Netlify serverless) that I have been updating and the Patreon API is giving me 401 errors about 60% of the time on the https://www.patreon.com/api/oauth2/v2/identity endpoint during testing on localhost. I have been trying to troubleshoot this for many hours and am wondering if it’s the API and not me.

When testing the app, I am getting 401s, but without changing anything, it will work as expected. I am getting back new tokens before sending a request to the identity endpoint. The tokens endpoint works with 100% success rate.

I am logging everything, every step of the way, and making sure the app is using the correct data. I have built multiple apps that use Patreon’s oAuth API for authentication.

I’m pretty sure I have everything setup correctly because it does work about 40% of the time. There is no pattern to the errors. It will work twice in a row and then error the next 5 times, then work once, then error the next 3. It seems that it is Patreon rejecting my ‘Authorization’ header on the identity endpoint.

Is this something that happens? Am I crazy? Is it my localhost environment that is causing my problems? It seems to be working in Production right now… I am not getting any complaints or seeing anything wrong in the logs. I just am having a hard time pushing something that is erroring 60% of the time to production.

Any help is appreciated.

Are you mixing v1 and v2 tokens, endpoints and calls? That can happen if you are mixing any of them.