feat: add OIDC resource server scope prefix for Cognito compatibility

When OIDC_RESOURCE_SERVER_ID is set, prefix resource scopes with the
identifier when forwarding to the IdP (e.g., calendar.read becomes
https://example.com/calendar.read). Required for IdPs like AWS Cognito
that mandate {resource_server_id}/{scope} format for custom scopes.
OIDC standard scopes (openid, profile, email) are forwarded as-is.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Chris Coutinho
2026-04-07 16:33:47 +02:00
co-authored by Claude Opus 4.6
parent 2f146f8408
commit e21ddd91b9
3 changed files with 18 additions and 1 deletions
+15 -1
View File
@@ -345,12 +345,26 @@ async def oauth_authorize(request: Request) -> RedirectResponse | JSONResponse:
f"Rewrote authorization endpoint for browser access: {authorization_endpoint}" f"Rewrote authorization endpoint for browser access: {authorization_endpoint}"
) )
# Prefix resource scopes with the resource server identifier if configured.
# Required for IdPs like Cognito that use {identifier}/{scope} format.
# OIDC standard scopes are forwarded as-is.
oidc_scopes = {"openid", "profile", "email"}
resource_server_id = os.getenv("OIDC_RESOURCE_SERVER_ID", "")
if resource_server_id:
idp_scope_list = [
f"{resource_server_id}/{s}" if s not in oidc_scopes else s
for s in scopes.split()
]
idp_scope_str = " ".join(idp_scope_list)
else:
idp_scope_str = scopes
# Redirect to Nextcloud with MCP server's own client_id (no PKCE — confidential client) # Redirect to Nextcloud with MCP server's own client_id (no PKCE — confidential client)
idp_params = { idp_params = {
"client_id": mcp_server_client_id, "client_id": mcp_server_client_id,
"redirect_uri": callback_uri, "redirect_uri": callback_uri,
"response_type": "code", "response_type": "code",
"scope": scopes, "scope": idp_scope_str,
"state": server_state, "state": server_state,
"prompt": "consent", "prompt": "consent",
"resource": f"{mcp_server_url}/mcp", # MCP server audience "resource": f"{mcp_server_url}/mcp", # MCP server audience
+2
View File
@@ -213,6 +213,7 @@ class Settings:
oidc_client_id: str | None = None oidc_client_id: str | None = None
oidc_client_secret: str | None = None oidc_client_secret: str | None = None
oidc_issuer: str | None = None oidc_issuer: str | None = None
oidc_resource_server_id: str | None = None
# Nextcloud settings # Nextcloud settings
nextcloud_host: str | None = None nextcloud_host: str | None = None
@@ -568,6 +569,7 @@ def get_settings() -> Settings:
"oidc_client_id": "NEXTCLOUD_OIDC_CLIENT_ID", "oidc_client_id": "NEXTCLOUD_OIDC_CLIENT_ID",
"oidc_client_secret": "NEXTCLOUD_OIDC_CLIENT_SECRET", "oidc_client_secret": "NEXTCLOUD_OIDC_CLIENT_SECRET",
"oidc_issuer": "OIDC_ISSUER", "oidc_issuer": "OIDC_ISSUER",
"oidc_resource_server_id": "OIDC_RESOURCE_SERVER_ID",
# Nextcloud settings # Nextcloud settings
"nextcloud_host": "NEXTCLOUD_HOST", "nextcloud_host": "NEXTCLOUD_HOST",
"nextcloud_username": "NEXTCLOUD_USERNAME", "nextcloud_username": "NEXTCLOUD_USERNAME",
+1
View File
@@ -37,6 +37,7 @@ oidc_issuer = "@none"
jwks_uri = "@none" jwks_uri = "@none"
introspection_uri = "@none" introspection_uri = "@none"
userinfo_uri = "@none" userinfo_uri = "@none"
oidc_resource_server_id = "@none"
# --- Mode flags --- # --- Mode flags ---
enable_multi_user_basic_auth = false enable_multi_user_basic_auth = false