oauth_proxy.rs A developer implemented an OAuth2 proxy service in Rust to handle MCP server authentication, intercepting requests to Auth0 to provide static credentials and fix compliance issues. The service replaces the `audience` parameter with `resource` and overrides the audience to match the CORE API, enabling smooth token generation without dynamic client registration. | /// Oauth2Service is a service that handles the proxying of oauth2 requests in the case of MCP server | | | /// We use/forward to Auth0 behind the scene but we need to intercept because: | | | /// We don't want to support dynamic client registration in auth0, as we should enable it for the whole tenant and it causes security implications | | | /// but we wants users to use it without having to give them our oauth2 client and secret id before hands | | | /// thus we need to fake it in this server and returns our static creds. So it provides a smooth experience. Other implementations seems to do it too | | | /// There is new rfc/spec in progress to paliate to this https://auth0.com/blog/cimd-vs-dcr-mcp-registration/ | | | /// | | | /// Auth0 is not Oauth2 MCP compliant by default. It uses audience as a parameter in the token request, but MCP/oauth2 expects resource | | | /// We want users to generate a token for the audience/api of the CORE, but it is not possible by default as client check the audience/resource is the same | | | /// as the hostname of this server. So we intercept the request and replace the audience/resource with the audience of the CORE. | | | pub struct Oauth2Service { | | | original oauth server: Uri, | | | current oauth server: Uri, | | | oauth client id: String, | | | oauth client secret: String, | | | oauth audience override: String, | | | http client: reqwest::Client, | | | response auth required: StatusCode, HeaderMap , | | | response oauth2 protected resources: Arc