Created
July 13, 2020 21:06
-
-
Save ossentoo/f09509d0d7006de10e5c844e8e6951b9 to your computer and use it in GitHub Desktop.
Revisions
-
ossentoo revised this gist
Jul 13, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ public class Program { const string WebAdminServerApi = "application.web.admin.ServerAPI"; public static async Task Main(string[] args) { -
ossentoo created this gist
Jul 13, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,49 @@ public class Program { const string WebAdminServerApi = "xperters.web.admin.ServerAPI"; public static async Task Main(string[] args) { var builder = WebAssemblyHostBuilder.CreateDefault(args); builder.RootComponents.Add<App>("app"); Configure(builder.Services, builder.Configuration); await builder.Build().RunAsync(); } public static void Configure(IServiceCollection services, IConfiguration configuration) { var apiBaseUri = configuration[Constants.ConfigKeyApiBaseUri]; services.AddAuthorizationCore(); services.AddBlazoredLocalStorage(); services.AddScoped<ApiAuthenticationStateProvider>(); services.AddScoped<AuthenticationStateProvider>(provider => provider.GetRequiredService<ApiAuthenticationStateProvider>()); services.AddHttpClient(WebAdminServerApi, client => client.BaseAddress = new Uri(apiBaseUri)) .AddHttpMessageHandler<BaseAddressAuthorizationMessageHandler>(); // Supply HttpClient instances that include access tokens when making requests to the server project services.AddTransient(sp => sp.GetRequiredService<IHttpClientFactory>() .CreateClient(WebAdminServerApi)); BindConfiguration(services, configuration); } private static void BindConfiguration(IServiceCollection services, IConfiguration configuration) { var accessToken = configuration[Constants.ConfigKeyAzureAdAccessTokenScope]; var authenticationOptions = new MsalAuthenticationOptions(); configuration.Bind(Constants.ConfigKeyAzureAd, authenticationOptions); services.AddMsalAuthentication(options => { options.ProviderOptions.Authentication = authenticationOptions; options.ProviderOptions.DefaultAccessTokenScopes.Add(accessToken); }); var tuple = new Tuple<string, MsalAuthenticationOptions>(accessToken, authenticationOptions); } }