I am having difficulty with the authorization code flow in Amazon Cognito. The workflow that I am trying to build is the following:
- A user authenticates with the built-in Cognito UI.
- Cognito redirects back with the authorization code.
- I send the code to server where it's exchanged for tokens using /oauth2/token endpoint.
I have created a client without client secret. I authenticate using the Cognito UI, get back the code, then send the following with Postman:
URL: https://MY-DOMAIN/oauth2/token
Method: POST
Headers:
Content-Type: application/x-www-form-urlencoded
Body:
grant_type=authorization_code&
client_id=<my-client-id>&
code=<code-from-cognito-ui>&
redirect_uri=<my-redirect-url>
I do not use Authorization since there's no client secret.
In return I receive:
Code: 400
Body: { "error": "invalid_client" }
The app client is allowed authorization code grant in the AWS Cognito console.