Duration 1:2:44

Identity with Identity Server 4 | Tutorial Part 1

64 209 watched
0
1.2 K
Published 10 Jan 2022

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. 👉Join our bi-monthly email club: https://signup.codewithjulian.com 🎉Check Out Further Resources: https://codewithjulian.com 👍If you enjoyed this tutorial, please like this video consider subscribing for more content like this! 😎Subscribe for endless .NET Tutorials: /c/CodewithJulian 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 Source code: https://github.com/iulianoana/CoffeeShopper-IS4 Slides: https://resources.codewithjulian.com/vid-aspnet-identity-is4-p1 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 7. Register the Service in Program.cs 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 10. Add Connection String to appsettings.json 11. Configure Program.cs 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 Discovery Document: https://localhost:5443/.well-known/openid-configuration 16. Add IdentityServer4 Configuration and SeedData - Seed.cs template: https://github.com/IdentityServer/IdentityServer4/blob/main/src/EntityFramework/migrations/SqlServer/SeedData.cs - Config.cs template: https://github.com/kevinrjones/SettingUpIdentityServer/blob/master/step-by-step-demo/identity/IdSWithIdentity/Config.cs 17. Setup the IdentityServer Seeding process - dotnet run Server/bin/Debug/net6.0/Server /seed --project Server 18. Setup the IdentityServer authentication flow - https://github.com/IdentityServer/IdentityServer4.Quickstart.UI 19. Update IdentityServer QuickStart code 20. Setup Program.cs for integration with the QuickStart code (Server) Useful Links: Identity Article: https://docs.microsoft.com/en-us/aspnet/core/security/authentication/identity?view=aspnetcore-6.0 - Playlist: /playlist/PL1EYnCfHLswwOz77bgfFbFqRnY3bXYHp3 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 27:49 – Register the Service in Program.cs 29:18 - Add an empty ASP.NET Web Project to the Solution 31:03 - Install IdentityServer4 Dependencies 32:23 - Add Connection String to appsettings.json 32:50 - Configure Program.cs 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 01:01:42 - Setup Program.cs for integration with the QuickStart code Credits: - Many thanks to Kevin Jones from Rock Solid Knowledge and his comprehensive tutorial series on IdentityServer. - Sound effects obtained from https://www.zapsplat.com - Icons designed by http://www.freepik.com and https://www.flaticon.com/ - Images from the artists on https://unsplash.com/

Category Education

Show more

Comments - 92
  • @
    @identityserver2 years ago 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
    ...
    7
  • @
    @Apheliont2 years ago Very concise and to the point. Definitely like it!
  • @
    @talkathiriify2 years ago Excellent tutorials, very clear and smooth explanation I like the way you teach materials.
    Thank you very much for your efforts and time.
    2
  • @
    @bolafahmilast year 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!!
  • @
    @isachells98592 years ago Heyia. Just what i was looking for, good stuff. thanks a lot!
  • @
    @ahmedifhaam7266last year 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. ...
  • @
    @Emil-ej5oflast year 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!
  • @
    @mrohailiqbal2 years ago Thanks a lot man. You are the hero. Keep it up
  • @
    @GuildOfCalamity2 years ago This is slowly becoming my favorite channel on Youtube.
    There's no way I would've figured all this out without Julian's help.
  • @
    @TheQuranVerses110 months ago The best tutorial I have ever watched, Thank you so much !
  • @
    @austinmrakpor48632 years ago You just made learning Identity Server4 very easy, thanks so much.
  • @
    @playerzzt126210 months ago finally a professional tutorial and not like these tutorials...normally you don't do it but for simplicity...thanks 🙏
  • @
    @ChrisHolcomb212 years ago 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.
  • @
    @DotnetistEnterprise2 years ago haven't watched yet but I already subscribe. wow.
  • @
    @margoumixlast year Good work! just at
    be sure to add those couple of lines before executing dotnet run builder.Services.AddAuthorization();
    builder.Services.AddControllers();
    otherwise you will have a build error
    alos ther is not need to add --project Server
    ...
  • @
    @attilaguba8562 years ago Hi!great tutorial! Are you not planning to do the same thing with asp before mvc ? And can you make a forgot and reset password implementation as well?
  • @
    @yuriiarestov347011 months ago 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.
    ...
  • @
    @ce3772 years ago Regarding the concept behind making a model class of the CoffeeShop entity (API/Models/CoffeeShopModel for DataAccess/Models/CoffeeShop) can you explain or provide a related link on why/how this is best practice? I think I get it but seems pretty redundant when you're dealing with possibly hundreds (or more) database entities. ...
  • @
    @CostaSparrow2 years ago Hello, thanks for the tutorial. Why did you choose Blazor Server over Blazor WASM? Are there any differences if I want to impelent the same architecture but with Blazor WASM as a client?
  • @
    @ngoctule33572 years ago Great video for the tutorial IdentityServer4. Can you tell me the name of this project structure?
  • @
    @LineshLanjewarlast year When I run the add migration command, I get an error
    Add-Migration InitialIdentityServerMigration -c PersistedGrantDbContext
    Multiple startup projects set.
    Using project 'Server' as the startup project.
    Build started...
    Build succeeded.
    No DbContext named 'PersistedGrantDbContext' was found.
    ...
    1
  • @
    @glenhong80282 years ago Hi...thanks for posting this. Exactly what I need. Just following along but the AddCoffeeShops is missing out of your Github? Any change of dropping that in?
  • @
    @ElCidPhysics902 years ago Really interesting, but IdentityServer4 doesn't appear to be available any longer???
  • @
    @ahmedifhaam7266last year 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.
  • @
    @mdzakariamasud832611 months ago Can you please make tutorial for openiddict?
  • @
    @cylemons80996 months ago Maybe this comment will help future users.
    I was using .NET 7 on Linux.
    I followed the tutorial all the way until 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 MaxFloat[T](System.Collections.Generic.IEnumerable`1[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.
    ...
  • @
    @Pblw2 years ago Thank you for the video!
    "Quickstart UI" does not contain new user registration and user management interfaces.
    How to "correctly" add this functionality yourself? Maybe there are some articles or videos. ...
  • @
    @EminoMeneko11 months ago Identity Server 4 is no more developed as of December 2022. Are there other alternatives (ideally usable for free or low cost for production) outside of Duende Identity Server ?
  • @
    @user-bs2gq4cj1b7 months ago kindly provide authentication using openiddict also, it will be more helpful.
  • @
    @hosseintasm42222 years ago Very good and thank you. Just why did you disable subtitles?
  • @
    @turkerkaraoglu16759 months ago at , why you did not use IdentityDbContext instead of dbcontext? If I asked too early, forgive me.Edit 1: I got my answer at . ...
  • @
    @srkbhayo2 years ago right now IdentityServer 6 version has come out, now known as Duence Identity. Can you please a tutorial to add that in .net 6 ? 1
  • @
    @ademvelikesim15782 years ago Thanks a lot man. Where is the Server Solution codes?
  • @
    @malathip40432 years ago i want to use auth plugin , vue frontend, .net core , mssql for backend, Can you suggest please.
  • @
    @treasure67595 months ago when i execute dotnet run Server/bin/Debug/net8.0/Server/seed --project Server in package manager console acces of scopped_supported is offline and claims_supported are empty i don't know where is the probleme i follow the tutorial step by step :/ ...
  • @
    @GabeHandle2 years ago Has classic .NET Identity been abandoned in .NET 6? Is there any reason it could not be used with Blazor?
  • @
    @mostafat55682 years ago Great Tutorial, can you tell me how to add roles into access token.
    I want to add authorize attribute with role or policy in api
  • @
    @manojsaro56092 years ago Hi , I'm a beginner, please help to solve my doubt that is "In how to add Quickstart files into the project"
  • @
    @user-vr3qe6hh1u10 months ago I don't know why but migration failed.
  • @
    @honfey2 years ago Hi, Julian, found that your video has lots of 's' sounds at the end of the words, and hearing that makes the ears painful. I am not sure whether this is the recording issue...
  • @
    @chessgamesonline58672 years ago confusing, where is roles? and how u control roles per user?
  • @
    @SponsorElite2 years ago Why Not identity Server 6?
    I mean 1mio. $ have Not so many companys
  • @
    @gomriria21972 years ago Identity server 4 is not maintained any more go for ids 5 or 6
  • @
    @faustogallotti29922 years ago Hi Julian, congratulation for the tutorial and a big Thank you,
    I started to prototype a my own Identity Server project following your project, I found only an issue at the end,
    Server Project --> Program.cs file, when I try to run the projects I get 2 error when I try to use the following code
    app.UseAuthorization();
    app.UseEndpoints(endpoints =>
    {
    endpoints.MapDefaultControllerRoute();
    });
    for both lines I get this error description :
    System.InvalidOperationException: 'Unable to find the required services. Please add all the required services by calling 'IServiceCollection.AddAuthorization' in the application startup code.'
    I need to add the follow instruction before the app is generated,
    builder.Services.AddMvc();
    can you have a look if is normal please?
    ...
  • @
    @nickgibbens35212 years ago At when Julian navigates to https://localhost:5443/.well-known/openid-configuration the returned JSON is beautified. Does anyone know how to do this? Mine is just one long string broken over several lines ...
  • @
    @doanmoon1912 years ago When run "Add-Migration InitalIdentityServerMigration -c PersistedGrantDbContect" => I got an error "No DbContext named 'PersistedGrantDbContect' was found.". Usually, we have to create DbContext first, isn't it? Why doesn't the demo do that? Where am I wrong?
    This is my version:
    <Project Sdk="Microsoft.NET.Sdk.Web">
    <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
    </PropertyGroup>
    <ItemGroup>
    <PackageReference Include="IdentityServer4" Version="4.1.2" />
    <PackageReference Include="IdentityServer4.AspNetIdentity" Version="4.1.2" />
    <PackageReference Include="IdentityServer4.EntityFramework" Version="4.1.2" />
    <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="6.0.5" />
    <PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="6.0.5" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.5" />
    <PackageReference Include="" Version="6.0.5">
    <PrivateAssets>all</PrivateAssets>
    <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    </ItemGroup>
    </Project>
    ...