up
This commit is contained in:
67
Program.cs
67
Program.cs
@ -1,73 +1,62 @@
|
||||
using decePubClient;
|
||||
using Microsoft.AspNetCore.Components.Web;
|
||||
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Text.Json;
|
||||
using Append.Blazor.Notifications;
|
||||
using Blazored.LocalStorage;
|
||||
using Blazored.Modal;
|
||||
using decePubClient.Extensions;
|
||||
using decePubClient.Models;
|
||||
using decePubClient.Services;
|
||||
using Microsoft.AspNetCore.Components.WebAssembly.Authentication;
|
||||
using Toolbelt.Blazor.Extensions.DependencyInjection;
|
||||
using Microsoft.AspNetCore.Components.Authorization;
|
||||
using Microsoft.AspNetCore.Components.Web;
|
||||
using Microsoft.AspNetCore.Components.WebAssembly.Authentication;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
using Microsoft.Extensions.Options;
|
||||
using SocialPub.ClientModels;
|
||||
using collAnon.Client.Services;
|
||||
|
||||
var builder = WebAssemblyHostBuilder.CreateDefault(args);
|
||||
builder.RootComponents.Add<App>("#app");
|
||||
// builder.RootComponents.Add<HeadOutlet>("head::after");
|
||||
builder.RootComponents.Add<HeadOutlet>("head::after");
|
||||
|
||||
builder.Services.AddBlazorDownloadFile();
|
||||
builder.Services.AddApiAuthorization();
|
||||
builder.Services.AddOptions()
|
||||
.AddAuthorizationCore(options =>
|
||||
{
|
||||
options.AddPolicy(Policies.IsAdmin, ExtensionMethods.IsAdminPolicy());
|
||||
options.AddPolicy(Policies.IsUser, ExtensionMethods.IsUserPolicy());
|
||||
options.AddPolicy(Policies.IsModerator, ExtensionMethods.IsUserModeratorPolicy());
|
||||
})
|
||||
.AddTransient<AppStatusService>();
|
||||
builder.Services.AddBlazoredLocalStorage(config =>
|
||||
{
|
||||
config.JsonSerializerOptions.WriteIndented = false;
|
||||
config.JsonSerializerOptions.PropertyNameCaseInsensitive = true;
|
||||
config.JsonSerializerOptions.IgnoreReadOnlyProperties = true;
|
||||
config.JsonSerializerOptions.ReadCommentHandling = JsonCommentHandling.Skip;
|
||||
config.JsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;
|
||||
})
|
||||
.AddBlazoredModal()
|
||||
//.AddScoped<TokenAuthStateProvider>()
|
||||
.AddScoped<CustomAuthenticationMessageHandler>()
|
||||
builder.Services.TryAddEnumerable(
|
||||
ServiceDescriptor.Singleton<IPostConfigureOptions<RemoteAuthenticationOptions<ApiAuthorizationProviderOptions>>,
|
||||
ApiAuthorizationOptionsConfiguration>());
|
||||
builder.Services.AddBlazoredLocalStorage(config =>
|
||||
{
|
||||
config.JsonSerializerOptions.WriteIndented = false;
|
||||
config.JsonSerializerOptions.PropertyNameCaseInsensitive = true;
|
||||
config.JsonSerializerOptions.IgnoreReadOnlyProperties = true;
|
||||
config.JsonSerializerOptions.ReadCommentHandling = JsonCommentHandling.Skip;
|
||||
config.JsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;
|
||||
})
|
||||
.AddScoped<TokenAuthStateProvider>()
|
||||
.AddScoped<MessagesService>()
|
||||
//.AddScoped<AuthenticationStateProvider>(provider => provider.GetRequiredService<TokenAuthStateProvider>())
|
||||
.AddScoped<AuthenticationStateProvider>(provider => provider.GetRequiredService<TokenAuthStateProvider>())
|
||||
.AddSingleton(typeof(CoalescingStringLocalizer))
|
||||
//.AddTransient<IHttpService, HttpService>()
|
||||
.AddHeadElementHelper(options => options.DisableClientScriptAutoInjection = true)
|
||||
.AddLocalization()
|
||||
.AddNotifications()
|
||||
.AddTransient<IStorage, Storage>()
|
||||
.AddLogging(lb => lb.SetMinimumLevel(LogLevel.Debug))
|
||||
.AddIndexedDb();
|
||||
|
||||
|
||||
builder.Services.AddOidcAuthentication(options =>
|
||||
{
|
||||
builder.Configuration.Bind("Local", options.ProviderOptions);
|
||||
options.ProviderOptions.Authority = "https://demo.identityserver.io";
|
||||
options.ProviderOptions.ClientId = "interactive.public";
|
||||
options.ProviderOptions.ResponseType = "code";
|
||||
options.ProviderOptions.DefaultScopes.Add("api");
|
||||
options.ProviderOptions.DefaultScopes.Add("email");
|
||||
options.ProviderOptions.DefaultScopes.Add("profile");
|
||||
});
|
||||
|
||||
builder.Services.AddHttpClient("default", client =>
|
||||
{
|
||||
client.BaseAddress = new Uri(builder.HostEnvironment.BaseAddress);
|
||||
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
||||
});
|
||||
|
||||
builder.Services.AddHttpClient("ComponentsWebAssembly_CSharp.ServerAPI", client =>
|
||||
{
|
||||
client.BaseAddress = new Uri("https://demo.identityserver.io");
|
||||
})
|
||||
//.AddHttpMessageHandler<BaseAddressAuthorizationMessageHandler>()
|
||||
.AddHttpMessageHandler<CustomAuthenticationMessageHandler>();
|
||||
|
||||
builder.Services.AddTransient(sp => sp.GetRequiredService<IHttpClientFactory>().CreateClient("ComponentsWebAssembly_CSharp.ServerAPI"));
|
||||
builder.Services.AddScoped<MessagesService>();
|
||||
builder.Services.AddSingleton(serviceProvider =>
|
||||
{
|
||||
var conf = serviceProvider.GetRequiredService<IConfiguration>();
|
||||
|
Reference in New Issue
Block a user