Service Registration
Service Registration
Section titled “Service Registration”The .NET SDK follows various .NET fundamentals, such as dependency injection (DI), logging, and configuration.
When you call the AddAccessManagement extension method, you’re adding all of the required interfaces and related services ot the IServiceCollection.
Basic Usage
Section titled “Basic Usage”To register the SDK interfaces, call AddAccessManagement:
using Shared;using Microsoft.Extensions.DependencyInjection;using Microsoft.Extensions.Hosting;using Microsoft.Extensions.Logging;
HostApplicationBuilder builder = Host.CreateApplicationBuilder(args);
builder.Service.AddAccessManagement(environment, consumerKey, consumerSecret, applianceUrl);
using IHost host = builder.Build();From any other class that is resolved through dependency injection can instantiate the needed interfaces:
public class MyClass{ private readonly IApplianceApi _decisionEnvine;
public MyClass(IApplianceApi decisionEngine) { _decisionEngine = decisionEngine; }}ASP.NET Core Middleware
Section titled “ASP.NET Core Middleware”The SDK can be used as middleware in an ASP.NET Core application. All policy decisions will be given the folling input object acessible in Rego:
{ "input": { "caller_auth" : { "claims" : [ // Claims from ASP.NET core user identity. { "claim" : "value" } ], "jwt" // Caller token. }, "appliance_auth" : { "claims" : [ // Claims from TID for the appliance application. { "claim" : "value" } ], "jwt" // Appliance application token. }, "path" : "", // URL path accessed "method" : "" // HTTP Method }}To register the middleware, call UseAccessManagement:
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddAccessManagement(environment, consumerKey, consumerSecret, applianceUrl);
var app = builder.Build();
app.UseAuthorization();app.UseAccessManagement("sample.authz", "allow");
app.MapControllers();
app.Run();A sample ASP.NET Core API can be found on Trimble GitHub Enterprise