-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMauiProgram.cs
93 lines (81 loc) · 3.14 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Identity.Client;
using BitBuggy.Shipping.Maui.ViewModels;
using BitBuggy.Shipping.Maui.Views;
using BitBuggy.Shipping.Maui.Shipping.Client;
using BitBuggy.Shipping.Maui.Shipping.Api;
using BitBuggy.Shipping.Maui.Shipping;
using Microsoft.Identity.Client.Extensions.Msal;
namespace BitBuggy.Shipping.Maui;
public static class MauiProgram
{
public const string ClientId = "8fb6f658-02b8-4a68-84ae-6d0a8b7a865e";
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
});
builder.Services.AddSingleton<IPublicClientApplication>(services =>
{
PublicClientApplicationBuilder builder = PublicClientApplicationBuilder
.Create(ClientId)
// B2C: Tenant Name: bitbuggy, Tenant ID: bitbuggy.onmicrosoft.com, use tfp
.WithB2CAuthority("https://bitbuggy.b2clogin.com/tfp/bitbuggy.onmicrosoft.com/B2C_1_BitBuggyLogin")
.WithRedirectUri($"msal{ClientId}://auth");
IPublicClientApplication app;
#if ANDROID
// Android Devices
app = builder
.WithParentActivityOrWindow(() => Platform.CurrentActivity)
.Build();
#elif IOS
// iOS - Uses AdalCache for MSAL
app = builder
.WithIosKeychainSecurityGroup("com.microsoft.adalcache")
.Build();
#else
// Windows, macOS, Linux
app = builder
.WithRedirectUri("https://bitbuggy.b2clogin.com/oauth2/nativeclient")
.Build();
#endif
StorageCreationProperties cacheProperties = new StorageCreationPropertiesBuilder("msal.cache", MsalCacheHelper.UserRootDirectory)
.WithLinuxKeyring(
"dev.bitbuggy.shipping.cache",
MsalCacheHelper.LinuxKeyRingDefaultCollection,
"BitBuggy Shipping Cache",
new("Version", "1"),
new("ProductGroup", "ShippingApp")
).Build();
#if WINDOWS
MsalCacheHelper helper = MsalCacheHelper.CreateAsync(cacheProperties).Result;
helper.RegisterCache(app.UserTokenCache);
#endif
return app;
});
// Services
builder.Services
.AddSingleton<AccountAuthorizationService>()
.AddSingleton<ShippingService>();
// Viewmodels
builder.Services
.AddSingleton<AccountViewModel>()
.AddTransient<TrackingViewModel>()
.AddTransient<EmployeeSearchViewModel>();
// Pages
builder.Services
.AddTransient<AccountPage>()
.AddTransient<TrackingPage>()
.AddTransient<EmployeeView>();
#if DEBUG
builder.Logging.AddDebug();
#endif
return builder.Build();
}
}