1+ using Microsoft . AspNetCore . Components . Authorization ;
12using Microsoft . AspNetCore . Components . WebAssembly . Authentication ;
23using Microsoft . AspNetCore . Components . WebAssembly . Hosting ;
34using MudBlazor . Services ;
45using NetEvent . Client ;
6+ using NetEvent . Client . Services ;
57
68var builder = WebAssemblyHostBuilder . CreateDefault ( args ) ;
79builder . RootComponents . Add < App > ( "#app" ) ;
810
11+
12+ builder . Services . AddOptions ( ) ;
13+ builder . Services . AddAuthorizationCore ( ) ;
14+ builder . Services . AddScoped < CustomStateProvider > ( ) ;
15+ builder . Services . AddScoped < AuthenticationStateProvider > ( s => s . GetRequiredService < CustomStateProvider > ( ) ) ;
16+ builder . Services . AddScoped < IAuthService , AuthService > ( ) ;
17+ builder . Services . AddTransient ( sp => new HttpClient { BaseAddress = new Uri ( builder . HostEnvironment . BaseAddress ) } ) ;
18+
19+
920builder . Services . AddHttpClient ( "NetEvent.ServerAPI" )
21+ . ConfigureHttpClient ( client => client . BaseAddress = new Uri ( builder . HostEnvironment . BaseAddress ) ) ;
22+
23+ builder . Services . AddHttpClient ( "NetEvent.ServerAPI.Secure" )
1024 . ConfigureHttpClient ( client => client . BaseAddress = new Uri ( builder . HostEnvironment . BaseAddress ) )
1125 . AddHttpMessageHandler < BaseAddressAuthorizationMessageHandler > ( ) ;
1226
13- // Supply HttpClient instances that include access tokens when making requests to the server project.
14- builder . Services . AddScoped ( provider =>
15- {
16- var factory = provider . GetRequiredService < IHttpClientFactory > ( ) ;
17- return factory . CreateClient ( "NetEvent.ServerAPI" ) ;
18- } ) ;
19-
20- builder . Services . AddOidcAuthentication ( options =>
21- {
22- options . ProviderOptions . ClientId = "NetEvent-blazor-client" ;
23- options . ProviderOptions . Authority = "https://localhost:44310/" ;
24- options . ProviderOptions . ResponseType = "code" ;
25-
26- options . UserOptions . RoleClaim = "role" ;
27- options . ProviderOptions . DefaultScopes . Add ( "roles" ) ;
28-
29- // Note: response_mode=fragment is the best option for a SPA. Unfortunately, the Blazor WASM
30- // authentication stack is impacted by a bug that prevents it from correctly extracting
31- // authorization error responses (e.g error=access_denied responses) from the URL fragment.
32- // For more information about this bug, visit https://github.com/dotnet/aspnetcore/issues/28344.
33- //
34- options . ProviderOptions . ResponseMode = "query" ;
35- options . AuthenticationPaths . RemoteRegisterPath = "https://localhost:44310/Identity/Account/Register" ;
36- } ) ;
37-
3827builder . Services . AddMudServices ( ) ;
3928
4029await builder . Build ( ) . RunAsync ( ) ;
0 commit comments