void SetupContext(TestContext ctx) { ctx.Services.AddSingleton <NavigationManager>(_navigationManager); var tenantStore = new InMemoryTenantStore(); tenantStore.TryAdd(new Tenant("company1", null)); ctx.Services.AddMultiTenantancy(tenantStore); ctx.Services.AddSingleton <INavigationInterception, TestNavigationInterception>(); ctx.Services.AddServiceProviderToMultiTenantRoutes(); }
public static async Task Main(string[] args) { var builder = WebAssemblyHostBuilder.CreateDefault(args); builder.RootComponents.Add <App>("app"); builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); var store = new InMemoryTenantStore(); var tenantSection = builder.Configuration.GetSection("Tenants"); foreach (var tenant in tenantSection.GetChildren()) { var authSection = tenant.GetSection("Auth"); store.TryAdd(new Tenant(tenant.GetValue <string>("Identifier"), new Dictionary <string, string>() { { "ApiUri", tenant.GetValue <string>("ApiUri") }, { "Auth.Authority", authSection.GetValue <string>("Authority") }, { "Auth.ClientId", authSection.GetValue <string>("ClientId") }, { "Auth.ResponseType", authSection.GetValue <string>("ResponseType") } })); } builder.Services.AddMultiTenantancy(store); builder.Services.Configure <RemoteAuthenticationOptions <OidcProviderOptions> >(options => { var tenant = _sp.GetRequiredService <Tenant>(); var nav = _sp.GetRequiredService <NavigationManager>(); if (!string.IsNullOrEmpty(tenant?.Identifier)) { options.ProviderOptions.ClientId = tenant.Parameters["Auth.ClientId"]; options.ProviderOptions.Authority = tenant.Parameters["Auth.Authority"]; options.ProviderOptions.ResponseType = tenant.Parameters["Auth.ResponseType"]; MultiTenantRemoteAuthenticationPaths.AssignPathsOptionsForTenantOrDefault(tenant, nav, options); } }); builder.Services.AddOidcAuthentication(options => { options.ProviderOptions.DefaultScopes.Clear(); options.ProviderOptions.DefaultScopes.Add("openid profile offline_access api"); }); var build = builder.Build(); _sp = build.Services; build.Services.AddServiceProviderToMultiTenantRoutes(); await build.RunAsync(); }