I have a Blazor Server-side app that uses a custom Identity provider for CosmosDB that does not use Entity Framework. I want to convert the app to Blazor WebAssembly hosted on Asp.net Core.
My Blazor Server-side Startup.cs custom provider looks like this:
services.AddTransient<IRoleStore<ApplicationRole>, CosmosDBRoleStore<ApplicationRole>>();
services.AddTransient<IUserStore<ApplicationUser>, CosmosDBUserStore<ApplicationUser>>();
services.AddIdentity<ApplicationUser, ApplicationRole>().AddDefaultTokenProviders();
services.AddAuthentication();
services.AddAuthorization();
The current template in Visual Studio for Blazor WebAssembly hosted on Asp.net Core uses Identity Server4 on top of Asp.Net Core Identity + SQL Server, and it requires a DBContext from Entity Framework Core.
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(
Configuration.GetConnectionString("DefaultConnection")));
services.AddDefaultIdentity<ApplicationUser>(options =>
options.SignIn.RequireConfirmedAccount = true)
.AddEntityFrameworkStores<ApplicationDbContext>();
services.AddIdentityServer().AddApiAuthorization<ApplicationUser, ApplicationDbContext>();
services.AddAuthentication().AddIdentityServerJwt();
I installed the custom Cosmos DB Identity provider, but the line
services.AddIdentityServer().AddApiAuthorization<ApplicationUser, ApplicationDbContext>();
Requires an Entity Framework DBContext to populate all parameters for IdentityServer4.
I analyzed four scenarios:
1) Use Entity Framework on top of my custom Identity Provider, but it would require almost a total recoding since it uses a deeply customized CosmosDB integration with custom Login/Logout/Signup etc.. pages
2) Use Identity Server4 on top of my custom Provider, but I'm new to it and the whole framework is complex and all the examples with Asp.Net Core Identity use Entity Framework as well and I can't figure out how to do it.
3) Drop my custom Identity provider and use Azure B2C. After some tests, I find it messy and difficult to customize, with popups and unbranded confirm emails. This would also nullify weeks of work on custom Profile edit pages.
4) Keep the project on Blazor Server-Side and do not migrate
Is there anything I'm missing that would help solve the problem? Any library that could help configuring IdentityServer4 with a custom Identity provider that do not use Entity Framework?
After days of tests, I was finally able to achieve what I wanted:
"Port a Blazor Server app to Blazor WebAssembly hosted on Asp.net Core, keeping my custom Asp.net Identity + CosmosDB provider, without using Identity Server 4 and Entity Framework."
I created a manual implementation of JWT tokens Authentication Service + State provider and hooked it to Asp.Net Core Identity.
I used this project as guide that contains a full working JWT implementation: