Blazor hosted WebAssembly - AddIdentityServer().AddApiAuthorization replacement.

Alex256 1 Reputation point
2021-09-06T15:57:20.887+00:00

I talked about standard template project Blazor WebAssembly hosted with Individual Account authentication type and NET5.0
Into server part there is a lines:

services.AddIdentityServer()
                .AddApiAuthorization<ApplicationUser, ApplicationDbContext>…

Where is ApplicationDbContext makes me using of server local database with EF.
Is there a way to use service istead? Something like this:
services.AddIdentityServer()
.AddApiAuthorization<ApplicationUser>
.CustomDataStore()
Look like “AddApiAuthorization” is not splitable.

Blazor
Blazor
A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
1,395 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Bruce (SqlWork.com) 56,531 Reputation points
    2021-09-07T01:16:43.093+00:00

  2. Brando Zhang-MSFT 2,956 Reputation points Microsoft Vendor
    2021-09-14T07:34:22.833+00:00

    Hi @Alex256 ,

    According to the AddApiAuthorization source codes, you could find the AddApiAuthorization method will also call the AddOperationalStore method to set the dbcontext .

    You said want to use service instead, I think this method not support service as the parameter now.The AddOperationalStore's parameter should be with any EF-supported database.

    More details about how to use this AddOperationalStore method, you could refer to this article.

    Notice: AddOperationalStore's first opinion should be ConfigureDbContext. ConfigureDbContext is the delegate of type Action<DbContextOptionsBuilder> used as a callback to configure the underlying ConfigurationDbContext. The delegate can configure the ConfigurationDbContext in the same way if EF were being used directly with AddDbContext, which allows any EF-supported database to be used.

    If you still want to custom this method to use some custom store, I suggest you could write an new extension method and create the IIdentityServerBuilder based on your requirement with some custom store. Details about how to do it, I suggest you could try to refer to this article and this article.