Advanced Configuration

Customizing Metrics

You may customize Coravel Pro's metrics to your liking, if you need something other than the defaults. Perhaps you want to customize the order of your metrics or simply exclude some of your metrics for now.

Clear Registered Metrics

In Configure() you should start by calling app.ClearMetrics() after app.UseCoravelPro().

This will clear any automatically registered metrics.

Add Metrics

Next, call app.UseMetric<SomeMetricType>() in the order that you want your metrics to appear in the user interface.

Example

app.UseCoravelPro();
app.ClearMetrics();
app
  .UseMetric<FirstMetric>()
  .UseMetric<SecondMetric>()
  .UseMetric<ThirdMetric>();

Authorizing Access

By default, Coravel Pro gives public access to it's routes. This is usually not what you want in production environments.

Implement IHasPermission

To easily add authorization to Coravel Pro, create a class that implements the interface Coravel.Pro.Features.Auth.Interfaces.IHasPermission.

This interface exposes one method:

bool HasPermission(HttpRequest request, ClaimsPrincipal claimsPrincipal);

You are supplied:

  • The full HTTP request
  • The ClaimsPrincipal - usually used to verify the current User.

You may make whatever checks you need - like verifying that the User has the "Admin" role.

Return true if the user/request has permission to use Coravel Pro.

Register Permissions

In ConfigureServices() call AddPermission<T> after AddCoravelPro:

services.AddPermission<AdminHasPermission>();

Here's what AdminHasPermission might look like:

public class AdminHasPermission : IHasPermission
{
    public bool HasPermission(HttpRequest request, ClaimsPrincipal claimsPrincipal)
    {
        return claimsPrincipal.Identity.IsAuthenticated && claimsPrincipal.IsInRole("Admin");
    }
}