-
Notifications
You must be signed in to change notification settings - Fork 285
feat: OAuth 2.0 Protected Resource Metadata handler - RFC 9728 #643
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat: OAuth 2.0 Protected Resource Metadata handler - RFC 9728 #643
Conversation
jba
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Just going to have a security person take a look.
|
@rolandshoemaker can you confirm that the CORS policy is acceptable? |
|
@wagnerjt Do you think this is a useful addition to the API? |
|
Hey @jba thanks for tagging me! I have code very similar to the server I have defined in the protocol.md to create the endpoint (the part that just dumps the struct to json). metadata := &oauthex.ProtectedResourceMetadata{
Resource: "https://example.com/mcp",
AuthorizationServers: []string{
"https://auth.example.com/.well-known/openid-configuration",
},
ScopesSupported: []string{"read", "write"},
}
http.Handle("/.well-known/oauth-protected-resource",
auth.ProtectedResourceMetadataHandler(metadata))For the CORS element, as described within the example of usage, there are plenty of ways to do it within go as well as other infra depending on how it is hosted. I personally leverage external infra/tooling for cors policy. So I will leave it up to you all on this helper |
|
@jba are we just waiting on @rolandshoemaker's review for this? I can nudge. |
rolandshoemaker
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CORS policy seems reasonable to me.
|
Thanks @rolandshoemaker. @jba, could you confirm this is good to go? Otherwise, I'll review next week. |
auth: add OAuth 2.0 Protected Resource Metadata handler with CORS support
This change adds support for RFC 9728 (OAuth 2.0 Protected Resource Metadata)
by introducing a new
ProtectedResourceMetadataHandlerthat serves the.well-known/oauth-protected-resourceendpoint.The handler includes built-in CORS support with
Access-Control-Allow-Origin: *by default, as OAuth metadata is public information meant for client discovery.
Documentation includes examples for using custom CORS policies with popular
middleware libraries (github.com/rs/cors and github.com/jub0bs/cors).
Changes:
ProtectedResourceMetadatastruct andProtectedResourceMetadataHandlerfunction in
auth/auth.goauth/auth_test.godocumentation in
examples/server/auth-middleware/The implementation follows RFC 9728 §3.1 for OAuth 2.0 Authorization Server
Metadata discovery, enabling clients to discover protected resource capabilities
and authentication requirements.