-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Program.cs
94 lines (82 loc) · 3.07 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
using System.Net.Http.Headers;
using Blorc.OpenIdConnect;
using Blorc.OpenIdConnect.DemoApp;
using Blorc.Services;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Serilog.Extensions.Logging;
using Serilog;
using Serilog.Core;
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#app");
var baseUrl = builder.HostEnvironment.BaseAddress;
builder.Services
.AddHttpClient<WeatherForecastHttpClient>(client => client.BaseAddress = new Uri(baseUrl))
// Add access token using this
.AddAccessToken();
// Or using this
// .CustomizeHttpRequestMessage(
// async (provider, request) =>
// {
// var userManager = provider.GetRequiredService<IUserManager>();
// var user = await userManager.GetUserAsync();
// if (user is not null)
// {
// request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", user.AccessToken);
// }
// });
builder.Services.AddBlorcCore();
builder.Services.AddAuthorizationCore();
builder.Services.AddBlorcOpenIdConnect(
options =>
{
builder.Configuration.Bind("IdentityServer", options);
options.RedirectUri = baseUrl;
options.PostLogoutRedirectUri = baseUrl;
options.AutomaticSilentRenew = true;
options.ResponseType = "code";
options.FilterProtocolClaims = true;
options.LoadUserInfo = true;
options.Scope = "openid profile demo-api";
options.TimeForUserInactivityAutomaticSignOut = 15000;
options.TimeForUserInactivityNotification = 10000;
/* Options below are not required, uncomment if you need them */
/*
// The resource parameter that will be sent to the auth request
options.Resource = "https://your-api.com";
// The extra query parameters that will be sent to the auth request
options.ExtraQueryParams = new Dictionary<string, string>
{
{ "foo", "bar" }
};
// The extra parameters that will be sent to the token endpoint
options.ExtraTokenParams = new Dictionary<string, string>
{
{ "resource", "https://your-api.com" }
};
*/
});
// Logging
var levelSwitch = new LoggingLevelSwitch
{
#if DEBUG
MinimumLevel = Serilog.Events.LogEventLevel.Debug
#else
MinimumLevel = Serilog.Events.LogEventLevel.Information
#endif
};
var logger = Log.Logger = new LoggerConfiguration()
.MinimumLevel.ControlledBy(levelSwitch)
.Enrich.WithProperty("InstanceId", Guid.NewGuid().ToString("n"))
.WriteTo.BrowserConsole()
.CreateLogger();
builder.Services.AddSingleton<ILoggerFactory>(new SerilogLoggerFactory(logger, false));
builder.Services.AddSingleton(typeof(ILogger<>), typeof(Logger<>));
var webAssemblyHost = builder.Build();
await webAssemblyHost
.ConfigureDocumentAsync(
async documentService =>
{
await documentService.InjectBlorcCoreJsAsync();
await documentService.InjectOpenIdConnectAsync();
});
await webAssemblyHost.RunAsync();