-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathProgram.cs
57 lines (52 loc) · 2.4 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
using BlazorWebAssemblyApp.Account;
using Core.Interface;
using Microsoft.AspNetCore.Components.WebAssembly.Authentication;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Services;
using System;
using System.Net.Http;
using System.Threading.Tasks;
namespace BlazorWebAssemblyApp
{
public class Program
{
public static async Task Main(string[] args)
{
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#app");
builder.Services.AddHttpClient("webapi", (sp, client) =>
{
client.BaseAddress = new Uri("https://localhost:44320");
}).AddHttpMessageHandler(sp =>
{
var handler = sp.GetService<AuthorizationMessageHandler>()
.ConfigureHandler(
authorizedUrls: new[] { "https://localhost:44320" },
scopes: new[] { "weatherapiread" });
return handler;
});
builder.Services.AddTransient<IWeatherForecastService, WeatherForecastService>(sp =>
{
var httpClient = sp.GetRequiredService<IHttpClientFactory>();
var weatherForecastServiceHttpClient = httpClient.CreateClient("webapi");
return new WeatherForecastService(weatherForecastServiceHttpClient);
});
builder.Services.AddOidcAuthentication(options =>
{
//// Configure your authentication provider options here.
//// For more information, see https://aka.ms/blazor-standalone-auth
builder.Configuration.Bind("Local", options.ProviderOptions);
options.ProviderOptions.Authority = "https://localhost:5001/";
options.ProviderOptions.ClientId = "blazorwebassemblyapp";
options.ProviderOptions.DefaultScopes.Add("openid");
options.ProviderOptions.DefaultScopes.Add("profile");
options.ProviderOptions.DefaultScopes.Add("weatherapiread");
options.ProviderOptions.PostLogoutRedirectUri = "/";
options.ProviderOptions.ResponseType = "code";
options.UserOptions.RoleClaim = "role";
}).AddAccountClaimsPrincipalFactory<UserAccountFactory>();
await builder.Build().RunAsync();
}
}
}