fix(oauth): support external URL override for TLS-terminating proxy d…#364
fix(oauth): support external URL override for TLS-terminating proxy d…#364michaelalinks wants to merge 3 commits intoAzure:mainfrom
Conversation
…eployments When aks-mcp is deployed behind a TLS-terminating reverse proxy (e.g. Envoy Gateway, AGIC), r.TLS is always nil so OAuth metadata endpoints incorrectly return http:// URLs. This causes MCP clients to reject the metadata. Add --oauth-external-url flag (and OAUTH_EXTERNAL_URL env var fallback) that, when set, is used as the base URL in both /.well-known/oauth-protected-resource and /.well-known/oauth-authorization-server responses instead of deriving the scheme from r.TLS. The existing request-derived logic is preserved as the fallback when the flag is not set. Expose the option in the Helm chart as oauth.externalURL. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
@microsoft-github-policy-service agree |
The /oauth/callback handler was attempting to exchange the authorization code with Azure AD server-side, which always failed with AADSTS9002313 because no code_verifier was included (PKCE is enforced on /authorize). The correct MCP OAuth proxy pattern is: 1. /authorize: store state → client redirect_uri, then forward to Azure AD with the server's own callback URL as redirect_uri 2. /oauth/callback: look up the client redirect_uri from state and 302 back to the client with code+state intact 3. The MCP client exchanges the code directly via /oauth2/v2.0/token using its own PKCE code_verifier Also removes generateSessionToken, writeCallbackSuccessResponse, writeCallbackErrorResponse, and exchangeCodeForToken which were only used by the old callback handler, along with the crypto/rand and encoding/base64 imports that served them. Updates and extends tests to cover the new relay behaviour including state consumption, error forwarding, and unknown state rejection. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Notes on the OAuth callback proxy fixAdding these notes to document three decisions made in the changes to Why
|
When aks-mcp is deployed behind a TLS-terminating reverse proxy (e.g. Envoy Gateway, AGIC), r.TLS is always nil so OAuth metadata endpoints incorrectly return http:// URLs. This causes MCP clients to reject the metadata.
Add --oauth-external-url flag (and OAUTH_EXTERNAL_URL env var fallback) that, when set, is used as the base URL in both /.well-known/oauth-protected-resource and /.well-known/oauth-authorization-server responses instead of deriving the scheme from r.TLS. The existing request-derived logic is preserved as the fallback when the flag is not set.
Expose the option in the Helm chart as oauth.externalURL.
Please see also the related open issue (running a custom image of these code changes): #365