From the course: Building and Securing RESTful APIs in ASP.NET Core
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Add a test user - ASP.NET Core Tutorial
From the course: Building and Securing RESTful APIs in ASP.NET Core
Add a test user
- [Narrator] The C data class adds some test data to the in-memory database each time the application starts up. We can use this same approach to add some test users to the database. I'll add the new method at the bottom of the C data class. This'll be private static async task add test users. And this will accept a role manager, which we need to get from the identity name space. This takes user role entity. Call this role manager. And we'll also get a user manager. (typing) Now, as a first check, let's make sure that there isn't any data in the database. If there is then we aren't working with the in-memory database and something has changed. So let's say data exists equals role manager dot roles dot any, or user manager dot users any. If there is data for some reason, we're just gonna bail. If not, we'll do two things: we'll add a test role and a test user. (typing) Role manager dot create async, we'll create a role. We'll say new user role entity, call this role admin. Then we'll…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
-
-
-
-
-
-
-
(Locked)
How HTTP authentication works3m 39s
-
(Locked)
Authentication for REST APIs3m 21s
-
(Locked)
Add Identity4m 51s
-
(Locked)
Add a test user3m 21s
-
(Locked)
Create a users collection5m 45s
-
(Locked)
Create a registration route6m 9s
-
(Locked)
Add OpenIddict4m 12s
-
(Locked)
Add a token endpoint2m 6s
-
(Locked)
Create a UserInfo route5m 28s
-
(Locked)
More about OpenID Connect2m 59s
-
(Locked)
Authorization using policies5m 19s
-
(Locked)
-