| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- using System;
- using System.Net.Http;
- using System.Collections.Generic;
- using System.Threading.Tasks;
- using System.Text;
- #if (!NoAuth && Hosted)
- using Microsoft.AspNetCore.Components.WebAssembly.Authentication;
- #endif
- using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
- using Microsoft.Extensions.DependencyInjection;
- #if (Hosted)
- namespace ComponentsWebAssembly_CSharp.Client
- #else
- namespace ComponentsWebAssembly_CSharp
- #endif
- {
- public class Program
- {
- public static async Task Main(string[] args)
- {
- var builder = WebAssemblyHostBuilder.CreateDefault(args);
- builder.RootComponents.Add<App>("app");
- #if (!Hosted || NoAuth)
- builder.Services.AddTransient(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
- #else
- builder.Services.AddHttpClient("ComponentsWebAssembly_CSharp.ServerAPI", client => client.BaseAddress = new Uri(builder.HostEnvironment.BaseAddress))
- .AddHttpMessageHandler<BaseAddressAuthorizationMessageHandler>();
- // Supply HttpClient instances that include access tokens when making requests to the server project
- builder.Services.AddTransient(sp => sp.GetRequiredService<IHttpClientFactory>().CreateClient("ComponentsWebAssembly_CSharp.ServerAPI"));
- #endif
- #if(!NoAuth)
- #endif
- #if (IndividualLocalAuth)
- #if (Hosted)
- builder.Services.AddApiAuthorization();
- #else
- builder.Services.AddOidcAuthentication(options =>
- {
- #if(MissingAuthority)
- // Configure your authentication provider options here.
- // For more information, see https://aka.ms/blazor-standalone-auth
- #endif
- options.ProviderOptions.Authority = "https://login.microsoftonline.com/";
- options.ProviderOptions.ClientId = "33333333-3333-3333-33333333333333333";
- });
- #endif
- #endif
- #if (IndividualB2CAuth)
- builder.Services.AddMsalAuthentication(options =>
- {
- var authentication = options.ProviderOptions.Authentication;
- authentication.Authority = "https:////aadB2CInstance.b2clogin.com/qualified.domain.name/MySignUpSignInPolicyId";
- authentication.ClientId = "33333333-3333-3333-33333333333333333";
- authentication.ValidateAuthority = false;
- #if (Hosted)
- options.ProviderOptions.DefaultAccessTokenScopes.Add("https://qualified.domain.name/api.id.uri/api-scope");
- #endif
- });
- #endif
- #if(OrganizationalAuth)
- builder.Services.AddMsalAuthentication(options =>
- {
- var authentication = options.ProviderOptions.Authentication;
- authentication.Authority = "https://login.microsoftonline.com/22222222-2222-2222-2222-222222222222";
- authentication.ClientId = "33333333-3333-3333-33333333333333333";
- #if (Hosted)
- options.ProviderOptions.DefaultAccessTokenScopes.Add("api://api.id.uri/api-scope");
- #endif
- });
- #endif
- await builder.Build().RunAsync();
- }
- }
- }
|