Okta Dev Community,
I have an intermittent issue with my implementation of Authorization Code flow with a Proof Key for Code Exchange (PKCE) [Overview | Okta Developer](Okta Guide Auth with Code PKCE). I have implemented this flow with native C++ desktop apps with great success and high reliability but I am trying to make a C# desktop app work the same way and I am getting intermittent success and failure with the following error:
{"error":"invalid_grant","error_description":"PKCE verification failed."}
My rate of success right now seems to be 60% failure to 40% success. The flow always fails after the POST to request the “access_token” and “id_token”. I don’t change anything in my code, for any consecutive tries but my success rate is around the same. I have searched online extensively with no success and my C# experience is limited, this seems to be the closest thing to an answer but I already tried “asycn” with “await” with no greater success [https://github.com/okta/okta-oidc-js/issues/804](PKCE Code Verification Failure).
Any ideas on what’s going on? (see code below)
Thanks in advance for the help!
Snippet of my code below
private async void completeAuth()
{
string tokenURL = orgURL + “oauth2/v1/token”;try { var client = new RestClient(tokenURL); client.Timeout = -1; var request = new RestRequest(Method.POST); request.AddHeader("Accept", "application/json"); request.AddHeader("Content-Type", "application/x-www-form-urlencoded"); request.AddParameter("grant_type", "authorization_code"); request.AddParameter("client_id", clientID); request.AddParameter("redirect_uri", redirectURL); request.AddParameter("code", code); request.AddParameter("code_verifier", codeVerifier); IRestResponse response = await client.ExecuteAsync(request); string resStr = response.Content; Console.WriteLine(resStr); if (resStr.Contains("id_token")) { Console.WriteLine("Success"); } } catch (Exception e) { Console.WriteLine("Error while POSTING"); }
}