question

Alex256-0796 avatar image
0 Votes"
Alex256-0796 asked BrandoZhang-MSFT commented

Blazor hosted WebAssembly - AddIdentityServer().AddApiAuthorization replacement.

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.

dotnet-aspnet-core-blazor
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Bruce-SqlWork avatar image
0 Votes"
Bruce-SqlWork answered Alex256-0796 commented
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Sorry for delayed post, I not received answer notification.

You talked about ASP.NET Core Identity but I asked about AddIdentityServer().AddApiAuthorization
I already replaced Core Identity with custom storage.

The problem is in AddApiAuthorization function - this function did a lot of things and used internal functions.

0 Votes 0 ·
BrandoZhang-MSFT avatar image
0 Votes"
BrandoZhang-MSFT answered BrandoZhang-MSFT commented

Hi @Alex256-0796 ,

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.


· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks for the answer.

I think this method not support service

Yes. It is exact the problem

c

reate the IIdentityServerBuilder based on your requirement with some custom store.

Then I come to another problem. The next lines is "replaced" automatically by AddApiAuthorization

.AddCorsPolicyService<MyCustomCorsPolicyService>()
.AddResourceStore<MyCustomResourcesStore>()
.AddPersistedGrantStore<MyCustomPersistedGrantStore>()
.AddDeviceFlowStore<MyCustomDeviceFlowStore>();

So I can not use default Blazor WASM hosted template. I must create all from scratch.

PS: How can I enable answer notification here?
0 Votes 0 ·

Hi @Alex256-0796,

So I can not use default Blazor WASM hosted template. I must create all from scratch.

II couldn't get your point, your requirement is you want to use custom store instead of DBcontext, so you could only create custom store which inherits all the store interface and then use it. I think this is all related with the server identity part which will not affect the Blazor WASM client app.
0 Votes 0 ·