Skip to content
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

authentication on the metrics endpoint #100

Open
impactmrj opened this issue Jan 18, 2019 · 1 comment
Open

authentication on the metrics endpoint #100

impactmrj opened this issue Jan 18, 2019 · 1 comment

Comments

@impactmrj
Copy link

Just testing the metrics.net library, curious if one can put authentication on the metrics endpoint? Below is our snippet in the configuration() method. What am I missing? My controller is expecting basic authentication but the metrics endpoint is allowing me to go to it.

        appBuilder.Use(typeof(AuthenticationMiddleware));
        appBuilder.UseCors(CorsOptions.AllowAll);

        Metric.Config
         .WithAllCounters()
         //.WithReporting(r => r.WithConsoleReport(TimeSpan.FromSeconds(30)))
         .WithOwin(m => appBuilder.Use(m), cfg => cfg
             .WithRequestMetricsConfig(c => c.WithAllOwinMetrics(), new[]
             {
                new Regex("(?i)^sampleignore"),
                new Regex("(?i)^metrics"),
                new Regex("(?i)^health"),
                new Regex("(?i)^json")
             })
             .WithMetricsEndpoint()
         );

        HttpConfiguration config = new HttpConfiguration();
        config.MapHttpAttributeRoutes();

        config.Routes.MapHttpRoute(
            name: "DefaultApi",
            routeTemplate: "api/{controller}/{id}",
            defaults: new { id = RouteParameter.Optional }
        );

        appBuilder.UseWebApi(config);
@Liwoj
Copy link
Contributor

Liwoj commented Jan 19, 2019

You are creating Metrics endpoint using Owin. Metrics is just one of the Owin handlers. For each request, Owin handlers are called in the order of registration. So problem is probably in your AuthenticationMiddleware not stopping the request before it reaches Metrics middleware...

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

No branches or pull requests

2 participants