Skip to content

fix: construct RFC 8414 metadata URL correctly for path-based issuers - #1206

Merged
howardjohn merged 1 commit into
agentgateway:mainfrom
kimsehwan96:fix/rfc8414-metadata-url
Mar 12, 2026
Merged

howardjohn merged 1 commit into
agentgateway:mainfrom
kimsehwan96:fix/rfc8414-metadata-url

Conversation

@kimsehwan96

Copy link
Copy Markdown
Contributor

Fixes #1205

The well-known suffix was appended to the end of the issuer URL instead of being inserted between the origin and path per RFC 8414 Section 3, which broke metadata discovery for any IdP with a path-based issuer (e.g. Authentik).

@kimsehwan96
kimsehwan96 requested a review from a team as a code owner March 12, 2026 07:26
Copilot AI review requested due to automatic review settings March 12, 2026 07:26

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes OAuth Authorization Server Metadata discovery for path-based issuer URLs in the MCP auth flow by constructing the RFC 8414 metadata URL using the issuer’s origin plus the well-known prefix plus the issuer path.

Changes:

  • Update authorization_server_metadata() to use an RFC 8414-compliant metadata URL builder.
  • Add rfc8414_metadata_url() helper for constructing the metadata endpoint from an issuer URL.
  • Add unit tests covering path-based issuers and trailing-slash handling.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +303 to +306
let origin = parsed.origin().ascii_serialization();
let path = parsed.path();
format!("{origin}/.well-known/oauth-authorization-server{path}")
},

Copilot AI Mar 12, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

url::Url::parse("https://idp.example.com") yields path of "/", so this currently produces .../.well-known/oauth-authorization-server/ (extra trailing slash). That differs from RFC 8414 Section 3 (no trailing slash for root issuers), contradicts the doc comment above, and changes the previous behavior. Consider special-casing path == "/" to append an empty path (or otherwise avoid adding the trailing "/").

Copilot uses AI. Check for mistakes.
Comment thread crates/agentgateway/src/mcp/auth.rs Resolved
Comment on lines +333 to +337
fn test_rfc8414_metadata_url_root_issuer() {
assert_eq!(
rfc8414_metadata_url("https://idp.example.com"),
"https://idp.example.com/.well-known/oauth-authorization-server/"
);

Copilot AI Mar 12, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test currently expects a trailing slash for a root issuer (.../oauth-authorization-server/), which doesn’t match RFC 8414 Section 3 and also contradicts the doc comment above that says root issuers should produce the same result as before. Update the expected value accordingly, and consider adding a companion case for an input issuer with a trailing slash (https://idp.example.com/).

Copilot uses AI. Check for mistakes.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

@howardjohn howardjohn left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@howardjohn
howardjohn merged commit 1712c72 into agentgateway:main Mar 12, 2026
20 of 22 checks passed
jordanbecketmoore pushed a commit to jordanbecketmoore/agentgateway that referenced this pull request Mar 12, 2026
…agentgateway#1206)

Fixes agentgateway#1205

The well-known suffix was appended to the end of the issuer URL instead
of being inserted between the origin and path per RFC 8414 Section 3,
which broke metadata discovery for any IdP with a path-based issuer
(e.g. Authentik).

Signed-off-by: kimsehwan96 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

authorization_server_metadata: RFC 8414 URL construction is incorrect for path-based issuers

3 participants