Skip to content
This repository was archived by the owner on Jul 10, 2024. It is now read-only.

Commit 153b0b7

Browse files
davidfowlDamianEdwards
authored andcommitted
Session 4 clean up
1 parent 737da55 commit 153b0b7

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

docs/4. Add auth features.md

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,6 @@ In this module we're going to add the capability for users to register and sign-
3030
## Organize the newly created files
3131
> Note the new files added to the project in the "Areas/Identity" folder. We're going to clean these up a little to better match this project's conventions.
3232
33-
1. Staying in `IdentityHostingStartup.cs`, add a call to configure the Identity UI to use Bootstrap 4:
34-
``` csharp
35-
services.AddDefaultIdentity<User>()
36-
.AddDefaultUI(UIFramework.Bootstrap4)
37-
.AddEntityFrameworkStores<IdentityDbContext>();
38-
```
3933
1. Delete the `_ValidationScriptsPartial.cshtml` file in the `/Areas/Identity/Pages` folder, as we already have one in our project's regular pages folder.
4034
1. Delete the `ScaffoldingReadme.txt` file.
4135

@@ -69,10 +63,25 @@ In this module we're going to add the capability for users to register and sign-
6963
```
7064

7165
### Generate the Entity Framework migration for our Identity schema
72-
> Now that we've modified the Identity model, we need to create the Entity Framework migration to create the matching database schema
73-
1. Ensure the project builds successfully
74-
1. Open a command prompt and run the following command to create the migration: `dotnet ef migrations add CreateIdentitySchema`
75-
1. Run the following command to create and update the database: `dotnet ef database update`
66+
67+
#### Visual Studio: Package Manager Console
68+
69+
1. In Visual Studio, select the Tools -> NuGet Package Manager -> Package Manager Console
70+
71+
1. Run the following commands in the Package Manager Console
72+
```console
73+
Add-Migration CreateIdentitySchema
74+
Update-Database
75+
```
76+
77+
#### Command line
78+
79+
1. Run the following commands in the command prompt:
80+
```console
81+
dotnet build
82+
dotnet ef migrations add CreateIdentitySchema
83+
dotnet ef database update
84+
```
7685

7786
### Add the authentication middleware
7887
> We need to ensure that the request pipeline contains the Authentication middleware before any other middleware that represents resources we want to potentially authorize, e.g. Razor Pages
@@ -110,7 +119,6 @@ In this module we're going to add the capability for users to register and sign-
110119
> Let's make it so the site allows creation of an admin user when there isn't one already. The first user to access the site will be deemed the administrator.
111120

112121
1. Create a new class `AdminService` in the `Services` folder. This class will be responsible for managing the creation key generation and tracking whether the site should allow creating admin users.
113-
1. Add code to the class that will create an appropriately long creation key and expose it via a property:
114122
``` c#
115123
public class AdminService
116124
{
@@ -156,7 +164,7 @@ In this module we're going to add the capability for users to register and sign-
156164
services.AddSingleton<IAdminService, AdminService>();
157165
```
158166

159-
> We now need to override the default Register page to add UI for accepting the admin creation key and verifying it when processing the request
167+
> We now need to override the default Register page to enable creating the admin account when the first user is registered.
160168

161169
1. Run the Identity scaffolder again, but this time select the `Account\Register` page in the list of files to override and select the `IdentityDbContext (FrontEnd.Data)`
162170
* On command line, run
@@ -329,7 +337,6 @@ In this module we're going to add the capability for users to register and sign-
329337
1. Register the custom `UserClaimsPrincipalFactory<User>` in the `IdentityHostingStartup` class:
330338
``` c#
331339
services.AddDefaultIdentity<User>()
332-
.AddDefaultUI(UIFramework.Bootstrap4)
333340
.AddEntityFrameworkStores<IdentityDbContext>()
334341
.AddClaimsPrincipalFactory<ClaimsPrincipalFactory>();
335342
```

0 commit comments

Comments
 (0)