I need the ability to share an auth token from my host app with a blazor wasm client that runs inside one of my pages. The main site is using Open Id (is an identity server).I have read and soooo many tutorials on this and have not yet gotten it to work.
The main thing I am trying to do is mimic what happens in a vanilla blazor wasm project straight out of visual studio that uses those PersistingServerAuthenticationStateProvider and such.
From what I can tell I have everything registered correctly. When I debug, I see my PersistingServerAuth object get activated and then disposed. When I navigate to the page that holds my blazor wasm, I would expect to see the markup contain the stuff. But it's missing.
On the blazor side, it looks like there is no authenticated user - I suspect because the authentication state is not being shared correctly.
Note that this setup is running inside of Orchard Core. So maybe OC is doing something that a regular asp.net core web app would do that is interrupting this state?
Here is my Startup.ConfigureServices method.
services.AddRazorComponents() .AddInteractiveServerComponents() .AddInteractiveWebAssemblyComponents();services.AddCascadingAuthenticationState();services.AddScoped<AuthenticationStateProvider, PersistingAuthenticationStateProvider>();services.AddSignalR();services.AddHttpsRedirection(options => { options.HttpsPort = 443; });services.AddOrchardCms() .AddSetupFeatures("OrchardCore.AutoSetup") .ConfigureServices(services => { services.AddAuthorization(options => { options.DefaultPolicy = new AuthorizationPolicyBuilder(new[] { JwtBearerDefaults.AuthenticationScheme }) .RequireAuthenticatedUser() .Build(); }); services.AddAuthentication(options => { options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme; }) .AddJwtBearer(options => { options.SaveToken = true; options.Authority = "https://localhost:4433/"; options.RequireHttpsMetadata = true; options.IncludeErrorDetails = true; options.TokenValidationParameters = new Microsoft.IdentityModel.Tokens.TokenValidationParameters() { ValidateIssuer = true, ValidateAudience = true, ValidateLifetime = true, ValidateIssuerSigningKey = true, ValidAudience = "crt_customer_portal", ValidIssuer = "https://localhost:4433/", ClockSkew = TimeSpan.Zero, IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("TODO_REPLACE_TODO_REPLACE")) //TODO Replace with real key }; }); }) .Configure((app, routes) => { app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseAuthentication(); app.UseAuthorization(); app.UseAntiforgery(); });Here is the startup inside my blazor wasm:
var builder = WebAssemblyHostBuilder.CreateDefault(args);builder.Services.AddAuthorizationCore();builder.Services.AddCascadingAuthenticationState();builder.Services.AddSingleton<AuthenticationStateProvider, PersistentAuthenticationStateProvider>(); await builder.Build().RunAsync();Any ideas what I might be missing? Could I be running into some conflict inside of Orchard Core?