using GiteaMcp.Config; using Microsoft.Extensions.Options; namespace GiteaMcp.Endpoints; /// /// OAuth 2.0 Authorization Server Metadata(RFC 8414)端点。 /// Claude.ai 在接入 custom connector 时会先访问 /.well-known/oauth-authorization-server, /// 根据返回的元数据找到 nas-auth 的 authorize / token / register 端点。 /// public static class DiscoveryEndpoints { public static IEndpointRouteBuilder MapDiscovery(this IEndpointRouteBuilder app) { app.MapGet("/.well-known/oauth-authorization-server", (IOptions opts) => { var o = opts.Value; return Results.Ok(new { issuer = o.Issuer, authorization_endpoint = o.AuthorizationEndpoint, token_endpoint = o.TokenEndpoint, registration_endpoint = o.RegistrationEndpoint, response_types_supported = new[] { "code" }, grant_types_supported = new[] { "authorization_code", "refresh_token" }, code_challenge_methods_supported = new[] { "S256" }, scopes_supported = new[] { "read:gitea" }, }); }); return app; } }