I can't suggest a resolution but I wanted to add that we are experiencing the exact same issue at the moment, except this is in production Java/Spring apps which use Microsoft OIDC to authenticate users. We've taken the same approach as you to troubleshooting and verified that the same intermittent error is occurring regardless of networking. Our best guess is Microsoft are rotating certificates and success depends entirely depending on which of their endpoints you hit with the call out. We have tried reaching out to Microsoft for assistance but so far got nowhere.