Skip to content

Ministack: Free, open-source local AWS emulator - 60+ services, Terraform compatible, real databases. Free forever. MIT licensed.

fix(cognito):OIDC autodiscovery parity (#588)

Nahuel Nucera1a72981330d1
diff --git a/ministack/app.py b/ministack/app.py
index fefcb252..f0a57255 100644
--- a/ministack/app.py
+++ b/ministack/app.py
@@ -550,7 +550,8 @@ async def _handle_cognito_get_request(method: str, path: str, headers: dict, que
pool_id = path.rsplit("/.well-known/openid-configuration", 1)[0].lstrip("/")
if pool_id:
region = extract_region(headers) or "us-east-1"
- return _get_module("cognito").well_known_openid_configuration(pool_id, region)
+ host = headers.get("host") or headers.get("Host")
+ return _get_module("cognito").well_known_openid_configuration(pool_id, region, host)
if path == "/oauth2/authorize" and method == "GET":
return _get_module("cognito").handle_oauth2_authorize(method, path, headers, query_params)
diff --git a/ministack/services/cognito.py b/ministack/services/cognito.py
index 518a7593..18bf6d68 100644
--- a/ministack/services/cognito.py
+++ b/ministack/services/cognito.py
@@ -159,18 +159,27 @@ def well_known_jwks(pool_id: str):
return 200, {"Content-Type": "application/json"}, json.dumps({"keys": [_JWKS_KEY]}).encode()
-def well_known_openid_configuration(pool_id: str, region: str | None = None):
- """Return OpenID Connect discovery document."""
+def well_known_openid_configuration(pool_id: str, region: str | None = None, host: str | None = None):
+ """Return OpenID Connect discovery document.
+
+ `issuer` matches the JWT `iss` claim (real AWS URL) so OIDC clients that
+ verify `iss == discovery.issuer` keep working. Endpoint URLs point at the
+ MiniStack gateway where /oauth2/authorize, /oauth2/token, /oauth2/userInfo
+ and /logout are actually served (added by PR #344). Real AWS serves these
+ on the pool-domain host; MiniStack serves them on the gateway.
+ """
r = region or get_region()
issuer = f"https://cognito-idp.{r}.amazonaws.com/{pool_id}"
+ base = f"http://{host}" if host else f"http://{_MINISTACK_HOST}:{_MINISTACK_PORT}"
+ pool_base = f"{base}/{pool_id}"
doc = {
"issuer": issuer,
- "jwks_uri": f"{issuer}/.well-known/jwks.json",
- "authorization_endpoint": f"{issuer}/oauth2/authorize",
- "token_endpoint": f"{issuer}/oauth2/token",
- "userinfo_endpoint": f"{issuer}/oauth2/userInfo",
- "end_session_endpoint": f"{issuer}/logout",
- "response_types_supported": ["code"],
+ "jwks_uri": f"{pool_base}/.well-known/jwks.json",
+ "authorization_endpoint": f"{base}/oauth2/authorize",
+ "token_endpoint": f"{base}/oauth2/token",
+ "userinfo_endpoint": f"{base}/oauth2/userInfo",
+ "end_session_endpoint": f"{base}/logout",
+ "response_types_supported": ["code", "token"],
"subject_types_supported": ["public"],
"id_token_signing_alg_values_supported": ["RS256"],
"scopes_supported": ["openid", "email", "phone", "profile"],
diff --git a/tests/test_cognito.py b/tests/test_cognito.py
index c597ed1f..2d3a6bd8 100644
--- a/tests/test_cognito.py
+++ b/tests/test_cognito.py
@@ -1117,6 +1117,9 @@ def test_cognito_openid_configuration():
assert pool_id in data["issuer"]
assert "jwks_uri" in data
assert "token_endpoint" in data
+ # AWS Cognito advertises both code and token grants
+ assert "code" in data["response_types_supported"]
+ assert "token" in data["response_types_supported"]
def test_cognito_browser_endpoints_send_cors_headers():