-
Notifications
You must be signed in to change notification settings - Fork 1
UserManagement Project
After UserManagement project is created then do the following.
- Delete the "Data" folder. We will utilize the class project IdentityUser100.
- Reference the IdentityUser class project in the UserManagement project.
- Change
ApplicationUsertoIdentityUserandApplicationDbContexttoIdentityUser100DbContext.
- Add the Authp NuGet Package, version 6.1.0.
- Create a "PermissionCode" folder and add
AppAuthSetupData.csandUserPermission.cs.
- Reference the AuthpServices class project.
- Examine program.cs and appsettings.json to identify added configurations.
- In the "Pages" folder, create the "HomeUI" folder and "TenantAdminUI."
- Add "TenantCreate.razor" in the "HomeController" folder. This user interface, TenantCreate.razor, can only be used by user who has
TenantCreatepermission. So there are only two users who can create tenant which are[email protected], and[email protected]. - Add "InviteUser.razor" and "AcceptInvitation.razor" in the "TenantAdminController."
These user interfaces are used when the tenant wants users to sign up only by invitation. - When first running the application, two users,
[email protected], and[email protected], will be created. Please change "EmailConfirmed" from False to True so that you can log in using these two users to create tenants. The password is the same as the username.
-
01/25/2024
-
On AuthPServices/SupportCode/AddUserServices, add CreateTenant and InviteUser classes. I just remove automatic signin from the original code. The reason is that when I create an invitation and accept invitation and the user is signin, I am forced to logout. I can not create another invitation. So for this testing environtment, I remove automatic signin.
-
Create a new class project, SharedServices. For now, I just add for email services so I can SendEmail and Admin Tenant or user can confirm the email.
-
To use email services you need to change to your real email sender.
Configure SMTP Settings in appsettings.json
"SMTP": { "Host": "mail.yourMailServer.com", "Port": "465", "User": "[email protected]", "Password": "AutpMailServerPassword123" },Update EmailMessageServices.cs in SharedServices/Services/Email
message.From.Add(new MailboxAddress("Sender", "[email protected]"));to your real email sender. -
User Interfaces.
I created two types of user interface, manually for testing and send by Email.- TenantCreate. Creating a tenant and confirmEmail using the code provided by samples from Microsoft.
- TenantCreateSendEmail. Creating a tenant, sending an email and confirming the Email.
- InviteUser. Inviting a user with only one input Email. The invitation link will direct users to the AcceptInvitation user interface.
- InviteUserByEmail. This interface has three inputs: Email, selecting InviteExpirationTime, and multiselect RoleNames. It creates an invitation link and sends it to an email.
- AcceptInvitation. his interface has two input fields: email and password. If the email matches the invitation email, the user will be created. To confirm, the user still has to click on ConfirmEmail.
- AcceptInvitationByEmail. If the user accepts the invitation from the email, the user will be redirected to this interface. Confirm Email will be done automatically.
So for my usecase, tenantcreate, InviteUser and AcceptInvitation are user interfaces for testing.
-
Authorization.
One nice feature of this authp library is that I can easily hide the navigation links if the user does not have permission. Initially, when the user does not have permission, they will be redirected to the 'AccessDenied' page because the user does not have permission. This can be inconvenient and frustrating for the user.
@if (user.HasPermission(UserPermissions.TenantList)) { <FluentNavLink Href="tenantlist" Icon="@(new Icons.Regular.Size20.PeopleCommunity())" IconColor="Color.Accent">Tenant List</FluentNavLink> } @if (user.HasPermission(UserPermissions.TenantCreate)) { <FluentNavLink Href="tenantCreate" Icon="@(new Icons.Regular.Size20.PeopleCommunityAdd())" IconColor="Color.Accent">Tenant Create</FluentNavLink> <FluentNavLink Href="tenantCreateSendEmail" Icon="@(new Icons.Regular.Size20.PeopleCommunityAdd())" IconColor="Color.Accent">Tenant Create By Email</FluentNavLink> } @if (user.HasPermission(UserPermissions.InviteUsers)) { <FluentNavLink Href="inviteUser" Icon="@(new Icons.Regular.Size20.PeopleCommunityAdd())" IconColor="Color.Accent">Invite User</FluentNavLink> <FluentNavLink Href="inviteUserByEmail" Icon="@(new Icons.Regular.Size20.PeopleCommunityAdd())" IconColor="Color.Accent">Invite User By Email</FluentNavLink> }