Skip to content

Amazon Cognito missing PKCE S256 in OIDC discovery metadata breaks MCP OAuth integration

0

Hi everyone,

I'm working on a personal MCP server hosted on Amazon Bedrock AgentCore Runtime, using Amazon Cognito for OAuth authentication.

Everything is configured with Authorization Code + PKCE, a Cognito Resource Server with a custom scope, and AgentCore's customJWTAuthorizer to validate access tokens.

However, I'm unable to connect the server to ChatGPT because Cognito's OIDC discovery endpoint doesn't include code_challenge_methods_supported.

ChatGPT rejects the connection with this error:

OAuth authorization server metadata must advertise PKCE support with code_challenge_methods_supported containing S256.

I verified the issue directly against my Cognito User Pool in us-east-1:

curl -s \
  "https://cognito-idp.us-east-1.amazonaws.com/<USER_POOL_ID>/.well-known/openid-configuration" \
  | jq '.code_challenge_methods_supported'

The result is null.

From what I understand, Cognito already supports PKCE with S256, so the issue seems to be specifically with the discovery metadata rather than the OAuth implementation itself.

I also tried hosting corrected OAuth metadata using CloudFront Functions, but that didn't solve the integration. AgentCore still advertises Cognito as the authorization server through its protected resource metadata, so ChatGPT continues discovering the original Cognito configuration.

I'd really like to keep the architecture entirely within AWS, without having to introduce an external identity provider or maintain a custom OAuth proxy just to work around a missing metadata field.

Is this a known issue with Amazon Cognito? Is there any supported workaround for using Cognito with MCP clients that strictly validate PKCE metadata?

Also, does anyone know whether AWS plans to include code_challenge_methods_supported: ["S256"] in the Cognito discovery document?

Any guidance would be appreciated. Thanks!

1 Answer
1
Accepted Answer

Yes, this is a known gap. Cognito supports PKCE with S256, but its discovery document doesn't include code_challenge_methods_supported. Strict MCP clients like ChatGPT reject that. I can't say whether AWS plans to add the field, since there's no public roadmap. A support case or feature request is the way to register interest.

Why the CloudFront fix didn't work

MCP clients find the authorization server in two steps:

  1. When an unauthenticated request gets a 401, the client reads the resource_metadata URL from the WWW-Authenticate header and fetches the protected resource metadata (PRM).
  2. The PRM's authorization_servers value is Cognito's issuer, so the client then fetches Cognito's discovery document and never sees your corrected one.

So publishing corrected metadata isn't enough. The client has to be directed to it by both the PRM and the 401 header.

A workaround that stays on AWS

Put CloudFront, with a custom domain, in front of the AgentCore Runtime endpoint, and have CloudFront Functions control discovery:

1. Serve your own PRM. At https://mcp.example.com/.well-known/oauth-protected-resource:

{
  "resource": "https://mcp.example.com/mcp",
  "authorization_servers": ["https://auth.example.com"],
  "scopes_supported": ["<your-resource-server>/<scope>"]
}

2. Serve your own authorization server metadata. At https://auth.example.com/.well-known/oauth-authorization-server, and optionally also at /.well-known/openid-configuration:

{
  "issuer": "https://auth.example.com",
  "authorization_endpoint": "https://<cognito-domain>/oauth2/authorize",
  "token_endpoint": "https://<cognito-domain>/oauth2/token",
  "jwks_uri": "https://cognito-idp.us-east-1.amazonaws.com/<POOL_ID>/.well-known/jwks.json",
  "response_types_supported": ["code"],
  "grant_types_supported": ["authorization_code", "refresh_token"],
  "code_challenge_methods_supported": ["S256"],
  "token_endpoint_auth_methods_supported": ["none", "client_secret_basic", "client_secret_post"]
}

issuer has to exactly match the URL the client used to find this document. That's why it's your own domain and not Cognito's. The actual authorization and token requests still go straight to Cognito.

3. Rewrite the 401 response. In a viewer-response function, replace the resource_metadata value in AgentCore's WWW-Authenticate header with your PRM URL. This is the piece that's usually missed. Without it, clients keep following AgentCore's PRM.

4. Proxy the MCP traffic. Forward /mcp to the AgentCore Runtime invocation endpoint, including the Authorization header.

Your customJWTAuthorizer doesn't need to change. It still validates Cognito-issued access tokens against Cognito's discovery URL. The facade only changes what the client finds during discovery.

One more thing to check: client registration

Cognito doesn't support Dynamic Client Registration (DCR). If ChatGPT only connects through DCR, you'll hit that next. Check whether its connector settings accept a pre-registered client ID: a public Cognito app client with no secret, PKCE, ChatGPT's callback URL, and your custom scope. If that works, the setup above is all you need. If DCR is required, the only AWS-only option is a small DCR Lambda that creates Cognito app clients. That's the custom OAuth component you wanted to avoid, so check this before building anything.

Is this worth doing?

The facade is a few static JSON documents plus a header rewrite, which is about as small as this workaround gets. Once Cognito adds the metadata field, you can remove it.

EXPERT

answered a month ago

EXPERT

reviewed a month ago

  • Hey, just wanted to come back and say thank you! Your comment really helped me figure this out.

    I ended up using a CloudFront Function as a proxy in front of AgentCore, handling the OAuth discovery endpoints, the 401 challenge, and advertising PKCE S256, while keeping Cognito for authentication.

    And it finally worked! I managed to connect my MCP server to ChatGPT successfully.

    I'd been stuck on this for quite a while, and your explanation pointed me in the right direction. Really appreciate you taking the time to help!

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.