JonPSmith / AuthPermissions.AspNetCore

This library provides extra authorization and multi-tenant features to an ASP.NET Core application.
https://www.thereformedprogrammer.net/finally-a-library-that-improves-role-authorization-in-asp-net-core/
MIT License
788 stars 159 forks source link

AuthP Assuming Cookie-Based IdentityUser #3

Closed AdamCollings closed 3 years ago

AdamCollings commented 3 years ago

While AuthP can be used with any authentication provider by implementing a custom ISyncAuthenticationUsers, when executing the finalise methods, such as SetupAspNetCoreAndDatabase it assumes the application is using cookies and IdentityUser which makes it unsuitable for services like Azure AD and B2C and causes the following exception.

System.AggregateException: 'Some services are not able to be constructed (Error while validating the service descriptor 'ServiceType: Microsoft.AspNetCore.Identity.IUserClaimsPrincipalFactory1[Microsoft.AspNetCore.Identity.IdentityUser] Lifetime: Scoped ImplementationType: AuthPermissions.AspNetCore.Services.AddPermissionsToUserClaims': Unable to resolve service for type 'Microsoft.AspNetCore.Identity.UserManager1[Microsoft.AspNetCore.Identity.IdentityUser]' while attempting to activate 'AuthPermissions.AspNetCore.Services.AddPermissionsToUserClaims'.)'`

JonPSmith commented 3 years ago

Hi @AdamCollings,

I have updated AuthP to work with Azure AD but I haven't released it yet. If you have time could you look at:

Let me know if anything looks iffy before I release this version.

PS. I'm planning on creating a video of how this works because I found setting up the Azure AD quite hard work!

JonPSmith commented 3 years ago

Version 1.3.0 is out and the docs are updated.