-
Notifications
You must be signed in to change notification settings - Fork 3
/
MauiProgram.cs
70 lines (60 loc) · 2.84 KB
/
MauiProgram.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
using BlazorHybridApp.Auth0;
using BlazorHybridApp.HttpDev;
using Core.Interface;
using Core.Model;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.AspNetCore.Components.WebView.Maui;
using Services;
namespace BlazorHybridApp
{
public static class MauiProgram
{
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
});
builder.Services.AddMauiBlazorWebView();
#if DEBUG
builder.Services.AddBlazorWebViewDeveloperTools();
#endif
builder.Services.AddAuthorizationCore();
builder.Services.AddSingleton<TokenProvider>();
builder.Services.AddScoped<Auth0AuthenticationStateProviderOptions>();
builder.Services.AddScoped<Auth0AuthenticationStateProvider>();
builder.Services.AddScoped<AuthenticationStateProvider>(sp =>
{
var tokenProvider = sp.GetRequiredService<TokenProvider>();
var auth0AuthenticationStateProviderOptions = sp.GetRequiredService<Auth0AuthenticationStateProviderOptions>();
auth0AuthenticationStateProviderOptions.Domain = "<YOUR_AUTH0_DOMAIN>";
auth0AuthenticationStateProviderOptions.ClientId = "<YOUR_CLIENT_ID>";
auth0AuthenticationStateProviderOptions.AdditionalProviderParameters.Add("audience", "<YOUR_AUDIENCE>");
auth0AuthenticationStateProviderOptions.Scope = "openid profile";
auth0AuthenticationStateProviderOptions.RoleClaim = "http://schemas.microsoft.com/ws/2008/06/identity/claims/role";
auth0AuthenticationStateProviderOptions.RedirectUri = "myapp://callback";
//auth0AuthenticationStateProviderOptions.RedirectUri = "http://localhost/callback"; // https://github.com/dotnet/maui/issues/8382
return sp.GetRequiredService<Auth0AuthenticationStateProvider>();
});
#if DEBUG
builder.Services.AddDevHttpClient("webapi", 7225);
#else
builder.Services.AddHttpClient("webapi", client =>
{
client.BaseAddress = new Uri("https://localhost:7225");
});
#endif
builder.Services.AddTransient<IWeatherForecastService, WeatherForecastService>(sp =>
{
var tokenProvider = sp.GetRequiredService<TokenProvider>();
var httpClientFactory = sp.GetRequiredService<IHttpClientFactory>();
var httpClient = httpClientFactory.CreateClient("webapi");
return new WeatherForecastService(httpClient, tokenProvider);
});
return builder.Build();
}
}
}