ASP.NET Identity with Identity Server 4 | Tutorial Part 1

preview_player
Показать описание
In this tutorial I will show you how to Configure ASP.NET Identity with Identity Server 4. The aim of this tutorial series is to ease up the Authentication process and provide a clear step-by-step process on how to secure your web applications. The entire tutorial will be done in .NET 6 and Blazor.

👍If you enjoyed this tutorial, please like this video consider subscribing for more content like this!

By the end of this tutorial, you will:
- Be able to integrate ASP.NET Identity with IdentityServer4
- Understand the components of a fully-secured .NET 6 application
- Understand the installation process for an IdentityServer4 project
- Be able to install the dependencies necessary for IdentityServer4

Steps:
Part 1: Setup the API
1. Create a new ASP.NET Core Empty project
2. Setup a ClassLibrary project for the Database
- Install-Package Microsoft.EntityFrameworkCore.SqlServer -Version 6.0.1
- Install-Package Microsoft.EntityFrameworkCore.Tools -Version 6.0.1
3. Add and Migrate an entity with EntityFramework Core
4. Add a CoffeeShop Service and Model
5. Create and Register API Controller (CoffeeShop)
6. Add CoffeeShops to the Database

Part 2 - Setting up the Identity Server (Server) project
8. Add an empty ASP.NET Web Project to the Solution
9. Install IdentityServer4 Dependencies (written bellow so you can just copy-paste them in your package manager console in the Server project)
Install-Package IdentityServer4 -Version 4.1.2
Install-Package IdentityServer4.EntityFramework -Version 4.1.2
Install-Package Microsoft.EntityFrameworkCore.Tools -Version 6.0.1
Install-Package Microsoft.EntityFrameworkCore.SqlServer -Version 6.0.1
Install-Package Microsoft.AspNetCore.Identity.UI -Version 6.0.1
Install-Package IdentityServer4.AspNetIdentity -Version 4.1.2
Install-Package Microsoft.AspNetCore.Identity.EntityFrameworkCore -Version 6.0.1
12. Create IdentityServer migrations (Default project: Server)
13. Update the IdentityServer Databases
14. Add ASP.NET Identity to the Server project
15. Add ASP.NET Identity migrations (Server proj) and run them
Add-Migration InitialAspNetIdentityMigration -Context AspNetIdentityDbContext
Update-Database -Context AspNetIdentityDbContext
16. Add IdentityServer4 Configuration and SeedData
17. Setup the IdentityServer Seeding process
- dotnet run Server/bin/Debug/net6.0/Server /seed --project Server
18. Setup the IdentityServer authentication flow
19. Update IdentityServer QuickStart code

Useful Links:

0:00 – Intro
0:50 – Components of this tutorial
4:03 - Create a new ASP.NET Core Empty project
6:09 - Setup a ClassLibrary project for the Database
13:32 – Add and Migrate an entity with EntityFramework Core
20:00 - Add a CoffeeShop Service and Model
24:11 - Create and Register API Controller (CoffeeShop)
25:57 - Add CoffeeShops to the Database
29:18 - Add an empty ASP.NET Web Project to the Solution
31:03 - Install IdentityServer4 Dependencies
35:48 - Create IdentityServer migrations
37:47 - Update the IdentityServer Databases
38:55 - Add ASP.NET Identity to the Server project
41:55 – Add ASP.NET Identity migrations
44:33 - Add IdentityServer4 Configuration and SeedData
51:41 - Setup the IdentityServer Seeding process
55:49 - Setup the IdentityServer authentication flow
56:53 - Update IdentityServer QuickStart code

Credits:
- Many thanks to Kevin Jones from Rock Solid Knowledge and his comprehensive tutorial series on IdentityServer.
Рекомендации по теме
Комментарии
Автор

Great Tutorial! Thank you for crediting Kevin in the description too! To answer some of the comments, Yes IdentityServer4 will no longer be supported by November 2022. However if you are a small organisation earning under $1 million USD or a single person, Duende IdentityServer is still free. There is also a collection of User & Client management tools to help you with configuring your IdentityServer solution. Duende's inbuilt UI, Skoruba, TheldServer and we also offer a free version of our AdminUI component.

- Kieran, Rock Solid Knowledge

identityserver
Автор

Maybe this comment will help future users.
I was using .NET 7 on Linux.
I followed the tutorial all the way until 53:57 and everything worked fine until there. But when running the program I got an exception at EnsureSeedData(Context) in the parts where you call .ToEntity(). The exception was something like this:

ArgumentException: GenericArguments[0], 'System.Char', on 'T violates the constraint of type 'T'.

What solved the problem for me was replacing IdentityServer4 with Duende.IdentityServer. and Remigrate the Database. Now that well known pages works fine.

cylemons
Автор

Just finished the tutorial, and oh man, paired with chatGPT following this through clearing questions about everything you were doing, including dependency injection, basic identity, even OOP concepts I was a bit confused with it took me 7 hours to fully complete this and learnt a lot, I am just a bit lost at the very end, why did we add that IS4 quickstart UI thing, I thought we were going to do a blazor server client in the part 2 anyway, thank you so much, about to watch part 2 now, very excited, maybe i'll find out why there. Thanks again. And yes I know IS4 is not supported anymore, but since main concepts seems to be used, this tutorial is anyway quite helpful, for plenty of reasons, highly recommended for new devs like me.

ahmedifhaam
Автор

finally a professional tutorial and not like these tutorials...normally you don't do it but for simplicity...thanks 🙏

playerzzt
Автор

The best tutorial I have ever watched, Thank you so much !

TheQuranVerses
Автор

I love how the tutorial is structured, the video description is REALLY helpful and saves A LOT of time, and the source code (and branches) are also so well made. Thanks!!

bolafahmi
Автор

Excellent tutorials, very clear and smooth explanation I like the way you teach materials.
Thank you very much for your efforts and time.

talkathiriify
Автор

This is such a lifesaving tutorial. Thanks! Almost all of this applies to the new duende ids that ive setup side by side with this tutorial. Thanks a million!

Emil-ejof
Автор

This is slowly becoming my favorite channel on Youtube.
There's no way I would've figured all this out without Julian's help.

GuildOfCalamity
Автор

Good work! just at
54:14 be sure to add those couple of lines before executing dotnet run

otherwise you will have a build error
alos ther is not need to add --project Server

margoumix
Автор

Nice tutorial. But will be even more helpful if you will provide some sort of connection diagram how the applications will work and how http request will travel. I'm trying to get into Identity Server 4, but without seeing the end result is difficult to understand what actually I'm trying to achive without going through the whole tutorial. The turorial is structured well, but in few spots more details will be very helpful. In example, for a person who already worked with Entity Framework it was easy to understand why we need all nuget packages, but extra word for each Identity Server package would help a lot to undestand why you added them into the project.
Anyway, one of the clearest Identity Server tutorials.

yuriiarestov
Автор

Very concise and to the point. Definitely like it!

Apheliont
Автор

Great video on using AspNetIdentity with IdentityServer 4 in DotNet Core 6. Explains very well on what pieces are needed and how they fit together.

ChrisHolcomb
Автор

You just made learning Identity Server4 very easy, thanks so much.

austinmrakpor
Автор

haven't watched yet but I already subscribe. wow.

DotnetistEnterprise
Автор

Heyia. Just what i was looking for, good stuff. thanks a lot!

isachells
Автор

Thanks a lot man. You are the hero. Keep it up

mrohailiqbal
Автор

When I run the add migration command, I get an error

Add-Migration -c PersistedGrantDbContext
Multiple startup projects set.
Using project 'Server' as the startup project.
Build started...
Build succeeded.
No DbContext named 'PersistedGrantDbContext' was found.

LineshLanjewar
Автор

Really interesting, but IdentityServer4 doesn't appear to be available any longer???

ElCidPhysics
Автор

When I ran the migration commands at first, there was also a designer.cs file, it goes into more detail on how to query db to create tables and what not, but why did I get this file generated and you did not.

ahmedifhaam