- Newest
- Most votes
- Most comments
Yes, Amazon Cognito's Managed Login does support the PKCE (Proof Key for Code Exchange) flow, which is recommended for single-page applications and mobile applications where you don't want to expose a client secret.
For your issue, there are a few things to check:
-
Make sure you've properly configured your app client to allow the authorization code grant with PKCE. This should be enabled in your app client settings.
-
When making the initial authorization request to the
/oauth2/authorizeendpoint, ensure you're including:
code_challengeparameter (the base64 URL-encoded SHA-256 hash of your code verifier)code_challenge_method=S256parameter
- When exchanging the authorization code for tokens at the
/oauth2/tokenendpoint, make sure you're including:
- The
code_verifierparameter (the original random string you generated) - The
codeparameter (the authorization code you received) - The
grant_type=authorization_codeparameter - The
client_idparameter - The
redirect_uriparameter (must match the one used in the authorization request)
The fact that adding the client secret makes it work suggests that your app client might be configured as a confidential client rather than a public client. For PKCE flow, you should configure your app client as a public client that doesn't require a client secret. Check your app client configuration to ensure it's set up correctly for PKCE.
If you've verified all these settings and are still experiencing issues, double-check the format of your token endpoint request, ensuring all parameters are correctly formatted and encoded.
Sources
Using PKCE in authorization code grants - Amazon Cognito
The redirect and authorization endpoint - Amazon Cognito
How authentication works with Amazon Cognito - Amazon Cognito
Choose an Amazon Cognito authentication flow for enterprise applications - AWS Prescriptive Guidance
answered a year ago
Cognito's Managed Login does support PKCE flow, but there are specific configuration requirements that might be causing your 400 error. Make sure you have setup the follow config properly:
-
Client Configuration: • Enable "Authorization code grant" • Set the client to "Public client" (not Confidential client which maybe the issue in your case)
-
Cross check if your token exchange request includes:
=================================
POST /oauth2/token Content-Type: application/x-www-form-urlencoded
grant_type=authorization_code &client_id=<your_client_id> &code=<authorization_code> &redirect_uri=<same_redirect_uri_used_in_auth_request> &code_verifier=<your_code_verifier>
=================================
Notes:
- If your client is configured as "Confidential," it will always require client_secret, even with PKCE
- Ensure your initial authorization request included code_challenge and code_challenge_method=S256
- The redirect_uri in token request must exactly match the one used in authorization request
answered a year ago
Relevant content
asked 2 years ago
- AWS OFFICIALUpdated 4 years ago
