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
770 stars 158 forks source link

Example 3 App Auth Setup Data - string not formatted Correctly #8

Closed nsfuntionality closed 2 years ago

nsfuntionality commented 2 years ago

I am trying to run the repo, but for some reason, it's not adding any user to the AuthUsers Table.

Error:

An error occurred while starting the application. AuthPermissionsBadDataException: True: Line/index 2, char: 1: The role App Admin wasn't found in the auth database. App Admin Line/index 1: The user AppAdmin@g1.com didn't have any roles. App Admin Line/index 3, char: 1: The role Tenant User wasn't found in the auth database. Tenant User
Line/index 2: The user extraUser@g1.com didn't have any roles. Tenant User Line/index 4, char: 1: The role Tenant Admin wasn't found in the auth database. Tenant Admin,Tenant User Line/index 4, char: 14: The role Tenant User wasn't found in the auth database. Tenant Admin,Tenant User
Line/index 3: The user admin@4uInc.com didn't have any roles. Tenant Admin,Tenant User Line/index 5, char: 1: The role Tenant User wasn't found in the auth database. Tenant User Line/index 4: The user user1@4uInc.com didn't have any roles. Tenant User Line/index 6, char: 1: The role Tenant User wasn't found in the auth database. Tenant User
Line/index 5: The user user2@4uInc.com didn't have any roles. Tenant User Line/index 7, char: 1: The role Tenant User wasn't found in the auth database. Tenant User Line/index 6: The user user1@Pets.com didn't have any roles. Tenant User Line/index 8, char: 1: The role Tenant User wasn't found in the auth database. Tenant User

Line/index 7: The user user1@BigR.com didn't have any roles. Tenant User AuthPermissions.CommonCode.ErrorReportingExtensions.IfErrorsTurnToException(IStatusGeneric status) in ErrorReportingExtensions.cs, line 63

AuthPermissionsBadDataException: True: Line/index 2, char: 1: The role App Admin wasn't found in the auth database. App Admin | Line/index 1: The user AppAdmin@g1.com didn't have any roles. App Admin Line/index 3, char: 1: The role Tenant User wasn't found in the auth database. Tenant User | Line/index 2: The user extraUser@g1.com didn't have any roles. Tenant User Line/index 4, char: 1: The role Tenant Admin wasn't found in the auth database. Tenant Admin,Tenant User | Line/index 4, char: 14: The role Tenant User wasn't found in the auth database. Tenant Admin,Tenant User | Line/index 3: The user admin@4uInc.com didn't have any roles. Tenant Admin,Tenant User Line/index 5, char: 1: The role Tenant User wasn't found in the auth database. Tenant User | Line/index 4: The user user1@4uInc.com didn't have any roles. Tenant User Line/index 6, char: 1: The role Tenant User wasn't found in the auth database. Tenant User | Line/index 5: The user user2@4uInc.com didn't have any roles. Tenant User Line/index 7, char: 1: The role Tenant User wasn't found in the auth database. Tenant User | Line/index 6: The user user1@Pets.com didn't have any roles. Tenant User Line/index 8, char: 1: The role Tenant User wasn't found in the auth database. Tenant User | Line/index 7: The user user1@BigR.com didn't have any roles. Tenant User AuthPermissions.CommonCode.ErrorReportingExtensions.IfErrorsTurnToException(IStatusGeneric status) in ErrorReportingExtensions.cs + throw new AuthPermissionsBadDataException(status.Errors.Count() == 1 AuthPermissions.AspNetCore.HostedServices.AddRolesTenantsUsersIfEmptyOnStartup.StartAsync(CancellationToken cancellationToken) in AddRolesTenantsUsersIfEmptyOnStartup.cs + status.IfErrorsTurnToException(); Microsoft.Extensions.Hosting.Internal.Host.StartAsync(CancellationToken cancellationToken) Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token) Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token) Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.Run(IHost host) Example3.MvcWebApp.IndividualAccounts.Program.Main(string[] args) in Program.cs + CreateHostBuilder(args).Build().Run();

JonPSmith commented 2 years ago

Hi @nsfuntionality,

I ran example 3 in my repo and it worked. I also deleted the database and ran it again to check it wasn't working because there was a database already there.

What I did find was I hadn't merged a change I had change for issue #4. Maybe that caused a problem. Please pull the latest commits and delete the database called "aspnet-Example3.MvcWebApp.IndividualAccounts-66CDC4E0-F9E0-486F-8199-D13455BF1415" and try again.

I'll leave this issue open until you say its OK.

nsfuntionality commented 2 years ago

so looks like that has fixed the issue is resolved. now in my project, I was using the NuGet package, is that also updated? OR do i need a make a new one from the repo and use that in my project?

JonPSmith commented 2 years ago

Great! Sorry about that.

The current AuthPermissions.AspNetCore NuGet package 1.4.0 contains the fixes - I just hadn't committed the code.

PS. I will be updating this library to EF Core 6, but I plan to add other features at the same time, like supporting PostgreSQL databases. That needs a big refactor of the code so it won't be soon.