I’m implementing the Authorization Code flow with PKCE for a single-page application that instruments Genesys Cloud API calls via New Relic. The initial authorization request to https://api.mypurecloud.com/oauth/authorize works fine, and I receive the code and state parameters in the redirect callback. However, when I attempt to exchange the code for an access token, the server returns a 400 Bad Request.
Here’s the POST request body I’m sending to https://api.mypurecloud.com/oauth/token:
{
"grant_type": "authorization_code",
"code": "AUTH_CODE_FROM_CALLBACK",
"redirect_uri": "https://myapp.local/callback",
"client_id": "MY_CLIENT_ID",
"code_verifier": "MY_CODE_VERIFIER"
}
The response is:
{
"error": "invalid_grant",
"error_description": "The authorization code has expired or was already used."
}
I’ve verified the following:
- The
code_verifiermatches thecode_challengesent in the initial request (S256 method). - The
redirect_uriis identical in both requests. - The request is made within 10 seconds of receiving the code.
- The
client_idis registered for the SPA application type.
Is there a specific timing constraint I’m missing, or could there be an issue with how the code_challenge is being generated? I’m using a standard SHA-256 hash base64url encoded.