.NET 8 Authentication with Identity in a Web API with Bearer Tokens & Cookies 🔒

แชร์
ฝัง
  • เผยแพร่เมื่อ 21 ม.ค. 2025

ความคิดเห็น • 175

  • @PatrickGod
    @PatrickGod  ปีที่แล้ว +43

    May, the fourth.. anybody? 🌌

    • @usamasuhaib3019
      @usamasuhaib3019 11 หลายเดือนก่อน +1

      sir please make a video for External Authentication with Yahoo in Asp net core

    • @joaomarcelofurtadoromero8277
      @joaomarcelofurtadoromero8277 หลายเดือนก่อน +1

      I got it, may the fourth be with you

    • @PatrickGod
      @PatrickGod  หลายเดือนก่อน

      @@joaomarcelofurtadoromero8277 This is the way. ❤️

  • @joaogabrielv.m328
    @joaogabrielv.m328 ปีที่แล้ว +48

    If everyone had the kind heart and the passion that Patrick has for teaching and .NET, the world surely would be a better place. Thanks as always, man!

    • @PatrickGod
      @PatrickGod  ปีที่แล้ว +11

      Hey João, thank you so much for your kind words! I'm really touched to hear that you appreciate the passion and effort I put into my tutorials. My ultimate goal is to make learning .NET and Blazor as accessible and enjoyable as possible. Knowing that I've made a positive impact on your learning journey means the world to me. Stay tuned for more content, and if you ever have any questions or topics you'd like me to cover, feel free to reach out. Happy coding! 🚀💻

    • @markhill1066
      @markhill1066 6 หลายเดือนก่อน

      My plumber: "While I'm fixing this garbage disposal, let me tell you about using a distributed cache."

  • @marcjohnston3292
    @marcjohnston3292 ปีที่แล้ว +5

    This is the absolute first anything I have ever subscribed to on TH-cam. This is perfect.

    • @PatrickGod
      @PatrickGod  ปีที่แล้ว

      Thank you so much!! Really appreciate it! 😄

  • @safiullah9275
    @safiullah9275 ปีที่แล้ว +48

    Great video! Would be great if you could add the following as well:
    1. Authorization roles, policies, etc
    2. Extending the existing feature set provided, like login/register/2fa and adding some own logic as well
    3. Creating and using our own UserEntity class instead of IdentityUser.
    4. Integrating it with Blazor 8 using the best practices
    Thanks!

    • @hfpsc27
      @hfpsc27 ปีที่แล้ว +2

      Yes. It would be great to see the same token/cookie working with other API's and a Blazor client (kind of a SSO).

    • @PatrickSch.
      @PatrickSch. ปีที่แล้ว +2

      Yes that that would be grat. Also how to use Authentication and Authorization in a seperate service (API) and connect it to the front end and also other services (APIs).

    • @orionnebula7167
      @orionnebula7167 8 หลายเดือนก่อน +1

      Halo, do you find a way using roles with this method, and is it possible at all???

  • @BrokenSword17
    @BrokenSword17 ปีที่แล้ว +5

    Hey Patrick. Thank you for everything you do and for being a cornerstone in the .NET community.

    • @PatrickGod
      @PatrickGod  ปีที่แล้ว +2

      Hey Jeffrey, thank you so much for the kind words! I'm humbled to hear that you consider me a cornerstone in the .NET community. My mission has always been to help others learn and grow in the field, and knowing that I've made a positive impact is incredibly rewarding. If you have any topics you're curious about or suggestions for future tutorials, please don't hesitate to share. Your feedback is invaluable. Thanks again for your support, and happy coding! 🚀💻

  • @nerdydragon42
    @nerdydragon42 ปีที่แล้ว +3

    Tried implementing this from an article I saw a while back and it didn't work, glad this came out!

  • @TheMezanine
    @TheMezanine ปีที่แล้ว +2

    Amazing, Microsoft did a great job with this feature in .Net 8, thanks Patrick for this introduction!!!

    • @PatrickGod
      @PatrickGod  ปีที่แล้ว

      Glad it was helpful!

  • @Wezo6666
    @Wezo6666 11 หลายเดือนก่อน +2

    You are so chilled man
    Brilliant videos

  • @hosseinghahari3557
    @hosseinghahari3557 6 หลายเดือนก่อน +1

    i searched alot , but you were just so perfect on this tutorial and i learned alot , you deserve like and sub , thx man

    • @PatrickGod
      @PatrickGod  6 หลายเดือนก่อน

      Thank you so much! Appreciate it. 😊

  • @leonidmisak2389
    @leonidmisak2389 ปีที่แล้ว +8

    Thanks, man! Very much appreciate your work!

  • @IlyaArlenka
    @IlyaArlenka ปีที่แล้ว +1

    When took some NZT pills and decided to become a developer :) Thanks a lot, Patrick!

  • @ViktorTy
    @ViktorTy ปีที่แล้ว +6

    I was waiting for this video!

  • @electrocatalyst
    @electrocatalyst ปีที่แล้ว +3

    Is there a way to use the new Identity Endpoints without EF? Eg. if I'm already using Dapper for db communication?

  • @TheWoodyj007
    @TheWoodyj007 ปีที่แล้ว +4

    Are there any examples of this that don't use EF? Some objects templates with something like Dapper?

  • @yafiecake
    @yafiecake 25 วันที่ผ่านมา +1

    so if I have application with auth + CRUD for blog posts, I will have 2 data classes? 1, inheriting from IdentityDbContext, then the other is just DbContext?

  • @CiaranTeachesCode
    @CiaranTeachesCode ปีที่แล้ว

    This is brilliant!
    It covers so many types of authentication in such a short video & it's easy to follow along with.
    Granted that it doesn't quite go in-depth with how the authentication types work properly but it shows how to implement it all, step by step, without any issues!
    Thanks for sharing this & keep doing what you do. You're helping so many developers/engineers, myself included 😁

    • @aymaniscoding424
      @aymaniscoding424 8 หลายเดือนก่อน

      so my project runs on Identity 2.2.0 (deprecated)
      I migrated my project from .NET 6 to .NET 8
      but still my code runs on the deprecated package.
      it feels scary to update it!
      I planning to add refresh token with my existing JWT
      how should I go about it ?

  • @philipatha
    @philipatha ปีที่แล้ว +3

    But how does the auth work across separate microservices? That would be good to know.

  • @bigfi2772
    @bigfi2772 ปีที่แล้ว +1

    Thank you for this instructive video. It's really nice how it's so simple now. I would really love a followup video explaining logging with google/MS/Apple or the two way authentification.

  • @garagamesdev
    @garagamesdev 7 หลายเดือนก่อน +1

    This tutorial saved my life. Thank you.

  • @hpannu
    @hpannu ปีที่แล้ว +2

    Can you please elaborate refresh token concept also. Once access token expires, how to implement refresh token thing?

  • @farahhashim7441
    @farahhashim7441 8 หลายเดือนก่อน +2

    Sooooooo Much Love from Pakistan
    you are really great teacher for me!😀😊

  • @sertunc-k5o
    @sertunc-k5o 10 หลายเดือนก่อน +31

    I wasted half a day because I added the wrong library. Be careful when adding libraries!!!

    • @willgordon5737
      @willgordon5737 5 หลายเดือนก่อน +1

      😂 if you open . Csproj file, you can see PackageReference tags, i just copy and paste from one project to another, as soon as you copy and save the proj file, it automatically install all the nuget packages.

  • @DotNetProgram
    @DotNetProgram 6 หลายเดือนก่อน

    You are the best...... Straight to point as always........ Love you man..... YOU are the BEST 😇

  • @maththaioseleutheriaphilos2320
    @maththaioseleutheriaphilos2320 ปีที่แล้ว +4

    It’s great, what You are showing here. Could You prepare tutorial how to use new authorisation in Blazor WebAssembly, please?

  • @luisedwards3534
    @luisedwards3534 9 หลายเดือนก่อน

    Thank you man, really appreciate your work!

  • @musab.salah1
    @musab.salah1 ปีที่แล้ว

    If i need add custom identity data like AplicationUser i need yo use a custom endpoint? Or there’s a way to do it on the built in endpoint!?

  • @Onlooker414
    @Onlooker414 6 หลายเดือนก่อน

    Has anyone actually tried to mirror the code? Got stuck at 4:41 as my VS IDE (.NET8) does not give me the same options (install packages for IdentityDbContext - those "using" instructions are not necessary, anyways if IdentityDbContext class is created in a separate file) as in the video. generates a lot of errors . Terrible. Total waste of time.

  • @nasermasri3816
    @nasermasri3816 11 หลายเดือนก่อน +4

    I am watching your tutorial when our baby also sleep:)

  • @scubaaddict
    @scubaaddict ปีที่แล้ว +2

    Hi, will this work in blazor 8, be great to see more info on how to implement auth in blazor web app. compared to blazor server and wasm. :)

  • @MatteoNanni-r1o
    @MatteoNanni-r1o ปีที่แล้ว +1

    A question, i have implemented it in my API project, but (i'm using controllesr too) i can't find the controller relative to the auth functions, or i have to create a service that inherits from the identity one ?

    • @leo.gaming
      @leo.gaming หลายเดือนก่อน

      Same question!

  • @FabioGamingFG
    @FabioGamingFG 3 หลายเดือนก่อน

    would there be a way to move those authentication endpoints into a controller?
    also is it possible to run middleware such as body decryption or header validation on this?

  • @OscarPlumariegaAcebo
    @OscarPlumariegaAcebo 6 หลายเดือนก่อน

    hi when i execute dotnet ef migrations add Inital, it remove all my dependencies or ef core, identity, design...what happens?

  • @astroimagers
    @astroimagers ปีที่แล้ว +2

    Timely. Thanks!

  • @bojanmirkovic3564
    @bojanmirkovic3564 10 หลายเดือนก่อน

    I am getting this error no matter what I do: A connection was successfully established with the server, but then an error occurred during the login process. (provider: SSL Provider, error: 0 - The certificate chain was issued by an authority that is not trusted.) // why?

  • @marciliojrr
    @marciliojrr ปีที่แล้ว +3

    Hi, @PatrickGod
    First, great video! Thanks for that.
    You told that token isn't a JWT. For professional applications, the mode showed in the video is safe?
    PS: Sorry for the english. I'm from Brazil, and I'm trying to write without Google Translator to learn.

    • @FilippoBellei
      @FilippoBellei 11 หลายเดือนก่อน +1

      Same question

  • @cryptoeric24
    @cryptoeric24 9 หลายเดือนก่อน

    Question, the section on cookies. Is the cookie stored on the server after valid email/password??? I don't see it in the response

  • @inyomanandiradita4426
    @inyomanandiradita4426 4 หลายเดือนก่อน

    Hi Patrick, Can we add relation between other table and identity user table?

  • @abdo.magdy.
    @abdo.magdy. ปีที่แล้ว +1

    can we configure it to use phone and otp for login instead of email/password?

  • @warrock0009
    @warrock0009 ปีที่แล้ว

    Did I miss something where we are setting IssuerSigningKey?

  • @LifeWithSeb99
    @LifeWithSeb99 10 หลายเดือนก่อน

    Is it possible to disable some of those "out of the box" controllers? 2fa for example..

  • @aymaniscoding424
    @aymaniscoding424 8 หลายเดือนก่อน

    so my project runs on Identity 2.2.0 (deprecated)
    I migrated my project from .NET 6 to .NET 8
    but still my code runs on the deprecated package.
    it feels scary to update it!
    I planning to add refresh token with my existing JWT
    how should I go about it ?

  • @dacamapo
    @dacamapo ปีที่แล้ว

    What id colors setup do you use?

  • @luisedwards3534
    @luisedwards3534 9 หลายเดือนก่อน

    Do you have a video of how to customize the /register controller generated by NetCore Identity?

  • @mohamedtahabouhamidi9478
    @mohamedtahabouhamidi9478 7 หลายเดือนก่อน

    Just a Question how can we protect the Register call from getting called by anyone ?

  • @kcbrown74
    @kcbrown74 8 หลายเดือนก่อน

    Excellent video, as usual!!! Thank you.

  • @leothlon
    @leothlon ปีที่แล้ว

    Thats nice, but how about when you need to use it in a real world situation with old user database and information? i need to make custom sql query requests to fetch a custom user object that i then need to access from my controllers? i can't just use identity database because my user database is used systems coded 15 years ago

  • @SquidSnipes
    @SquidSnipes 8 หลายเดือนก่อน

    What about m2m and reference tokens? Also what about protecting api resources and using introspection to authenticate tokens? Also what about scopes

  • @osamamirza4220
    @osamamirza4220 ปีที่แล้ว

    Awesome and informative as always!! 💯❤

  • @imagicd
    @imagicd 9 หลายเดือนก่อน +1

    Hmn, I don't want the generating authentication register/login. I have the table User in my database, how to use it for authentication?

    • @leo.gaming
      @leo.gaming หลายเดือนก่อน

      same question !

  • @geepy5708
    @geepy5708 11 หลายเดือนก่อน +1

    How do you change the time the token expiresIn, it is 3600 by default. Also can you add roles using this method?

    • @orionnebula7167
      @orionnebula7167 8 หลายเดือนก่อน

      Asking after 3 months, do you find a way using roles with this method, and is it possible at all???

  • @jayalakshmikarthikeyan-v2w
    @jayalakshmikarthikeyan-v2w 6 หลายเดือนก่อน

    Hi, Thanks for the video. After authorizing , am not getting lock symbol in weatherforcost method. and still shows lock open and shows 401. But Authorized when i send Bearer and Token.Could you please help me to fix this. Thank you

  • @peymannaji
    @peymannaji 9 หลายเดือนก่อน

    I made the settings for Swagger like as you did, but it doesn't send the authorization header. And it only works with Postman. And I would like to ask you a tutorial about role-based authentication.

  • @NecquiTeja
    @NecquiTeja ปีที่แล้ว

    Thanks Patrick for this wonderful tutorial.

  • @ІванЧернов-м6м
    @ІванЧернов-м6м 11 หลายเดือนก่อน

    Why don't i have an authorization controller? There are no routs such as login, register, etc.

  • @williambraun6593
    @williambraun6593 9 หลายเดือนก่อน

    Hi Patrick, is it possible to invalidate bearer tokens created with this method? I am trying to create a logout endpoint for my app but I can't find a way to do this.

  • @ivandrofly
    @ivandrofly 2 หลายเดือนก่อน

    Cool stuff - thanks :)

  • @nicko9958
    @nicko9958 9 หลายเดือนก่อน

    When should I use Bearer Tokens instead of JWT?

  • @LearnwithJames-k9n
    @LearnwithJames-k9n 4 หลายเดือนก่อน +1

    Thanx for another great video!!!👍👍

    • @PatrickGod
      @PatrickGod  4 หลายเดือนก่อน

      So nice of you.Thanks!

  • @boluwadekujero1717
    @boluwadekujero1717 11 หลายเดือนก่อน

    thank you for this wonderful tutorial. I am however having issues replicating it fully. Everything works except authorization. I login and receive token. I use the token to authorize the swagger. But when I try to execute the weatherforcast endpoint, I receive the 401 response "Unauthorized" response. I have tried replicating your tutorial twice with different new projects and the result is the same. Please advise. Thanks

  • @6shawry
    @6shawry ปีที่แล้ว +1

    Hi Patrick, thanks so much for the video. I just have a quick question, with these new security controllers, is there a way for us to be able to override the default logic? E.g. if I wanted a bespoke /register controller

  • @soumyadeeproy7605
    @soumyadeeproy7605 6 หลายเดือนก่อน

    Hey, how can I add it to an existing web api ?

  • @whosgotrythm
    @whosgotrythm 6 หลายเดือนก่อน

    Thank you for using controllers! No enterprise application I know of using minimal apis

  • @kerpackie
    @kerpackie ปีที่แล้ว +2

    Would you consider doing a video on implementing custom OAuth identity providers in Blazor WASM Hosted, similar to your Google OAuth video, but for non-standard OAuth providers, such as Discord, Battlenet, Github, etc.

  • @lazzy_Dev
    @lazzy_Dev 7 หลายเดือนก่อน

    Is there a demo on how to setup .net 8 api with identity to google oauth with react frontend ?

  • @saschaheimann4120
    @saschaheimann4120 9 หลายเดือนก่อน

    Hello Patrick,
    I'm a huge fan of your videos. I've bought a course on udemy too. In this case the video is nice and helpful too. But it would be good to let people know that using duende identity api's can be a license thema. So if you develop an open source application you've to inform everyone that if you use that application in a commercial context, depending on the size of your comopany you've to pay license fees to duende!
    I would be very thankful, If you can make a video about Authentication and Authorization without Duendes Identity API's in .NET8.
    Wish you all the best and thanks for your videos!

  • @Alakeks
    @Alakeks ปีที่แล้ว

    Hi, Does anyone have a hint how to limit options from this new identity for example to to delete two factors methods endpoint?

  • @oJutiz
    @oJutiz 5 หลายเดือนก่อน +1

    Amazing content, thanks a lot

    • @PatrickGod
      @PatrickGod  5 หลายเดือนก่อน

      My pleasure!

  • @kirillzlobin7135
    @kirillzlobin7135 11 หลายเดือนก่อน

    You did not install anything to use IdentityDBContext. Is it a built in thing?

  • @xxmaniakaxx9781
    @xxmaniakaxx9781 8 หลายเดือนก่อน

    Hey is the refresh token working by itself too and refreshes the bearer automatically if it is expired ?

  • @xanhxanh5097
    @xanhxanh5097 ปีที่แล้ว +1

    please continue this tutorial make a part 2, to integrate it into a spa :D:D

  • @kennethlooney6769
    @kennethlooney6769 8 หลายเดือนก่อน

    Hi Patrick! I can't figure out how to change the time the token expires from 3600 to something like 30 days. I tried even to ask Copilot but it gives me wrong source code to change it. I even told it that I am using .NET 8. If you could give me a hint how to do it in .NET 8 it be great.

  • @LegitoTV
    @LegitoTV 11 หลายเดือนก่อน

    Hi Patrick!
    This is pretty new to me as I am used to making my own code that does those functions.
    How do you configure the Register controller?
    For example lets say I want to also execute some other code when registration happens, or change the password requirements. How can I do that?

  • @don_Halapenjo
    @don_Halapenjo 9 หลายเดือนก่อน

    Very useful guide, thank you!

  • @enesbesirevic7915
    @enesbesirevic7915 7 หลายเดือนก่อน

    How can I retrive JWT insted of this bearer string?

  • @mycwid
    @mycwid 5 หลายเดือนก่อน

    Great video. Any pointers how to actually send an email when new user Registers new account? I am unable to view Register action and its unclear how to inject email action compared to a Web App. Thank you

  • @sachinkamboj8426
    @sachinkamboj8426 9 หลายเดือนก่อน

    That was amazing although faced few issues like separate DAL and lib version 7.0.11 . But I am able to achieve this with dotnet 8 and Postgress db Thanks

  • @TheLastEmperorXiXinPig
    @TheLastEmperorXiXinPig ปีที่แล้ว

    Need some guidance. If I want to use Identity in this way but instead of a password, use a one-time code instead, how could I achieve this, would appreciate any tips.

  • @FahadKhan-fq4zw
    @FahadKhan-fq4zw 11 หลายเดือนก่อน

    Hi great tutorial, I followed all the steps but after launching the API I didn't get endpoint like register , login etc. I only have default weatherforcast. Is there anything else I have to do to get other authentication end points.
    Thanks

  • @azizhmidi5835
    @azizhmidi5835 7 หลายเดือนก่อน

    How can you modify these endpoints??? I want to add username but I couldn't do it :(, would be amazing if you make a video about it!

  • @moatasemkremed5395
    @moatasemkremed5395 ปีที่แล้ว

    How do you scaffold identity API Endpoints

  • @jseh_
    @jseh_ 9 หลายเดือนก่อน

    but now how i disable identity register route?

  • @HaeriStudios
    @HaeriStudios ปีที่แล้ว +1

    Great Tutorial!
    Would love to see social login next.
    Dumb question, how do you log out again with a httpOnly cookie?

  • @mrcoulson58
    @mrcoulson58 9 หลายเดือนก่อน

    Super tutorial. One question: how can we set the expiresIn value to something besides 3600?

    • @mrcoulson58
      @mrcoulson58 9 หลายเดือนก่อน

      Got it. For anyone else struggling:
      builder.Services.ConfigureAll(option =>
      {
      option.BearerTokenExpiration = TimeSpan.FromDays(1);
      });

  • @thegoatmachine980
    @thegoatmachine980 8 หลายเดือนก่อน

    You are the best. Thank you!

  • @MB-nw5sz
    @MB-nw5sz ปีที่แล้ว

    Great video, thanks Patrick. There seems to be one missing piece of the puzzle though. This is great from Swagger, but - when you need to send the cookie (as Bearer), then how is it possible to grab the aspnet cookie - from Wasm especially - to be able to pass it? I can't find anyway from Wasm to be able to grab the cookie (apart from AFTER rendered, via JsInterop which is too late - unless i'm missing something)

  • @ahmedshehata5601
    @ahmedshehata5601 8 หลายเดือนก่อน

    what if i want to make role for every user like ( ... Admin , User , SuperAdmin )

  • @minhtuan389
    @minhtuan389 5 หลายเดือนก่อน

    It's a handy tutorial. Could you tell me how I can custom API, such as I don't want to allow normal users to access the register API, only the admin or manager can access it?

  • @I-PixALbI4-I
    @I-PixALbI4-I 11 หลายเดือนก่อน

    So i have no access to those methods from the code?
    How to add Roles, Claims etc? o_0

  • @alkmyalcn3275
    @alkmyalcn3275 9 หลายเดือนก่อน

    Hey Patrick thank you so much for great explanation of Authentication Flow with Identity in .NET 8 Web Api !! 👌Can you please explain or make a tutorial with MongoDb version of this one and/or the key points of implementation of MongoDb?

  • @amirameri1354
    @amirameri1354 7 หลายเดือนก่อน

    dear Patrick . Tank you for your great videos . I have one problem : How can i register and login user in blazor app server .net8 with api ? i want authorized API when user login to website . so i want create role for user that for example just admin access to [httppost] in controller.internal api or external api not defferent . Tank you very much

  • @_rachid
    @_rachid 9 หลายเดือนก่อน

    That's cool. Nice feature.
    Thank you.

  • @Ioannis-q9v
    @Ioannis-q9v 10 หลายเดือนก่อน

    Great tutorial!! Thx

  • @vivekkaushik9508
    @vivekkaushik9508 ปีที่แล้ว +2

    Great video Patrick. However, I must ask what was the improvement that has been made compared to previous version of dotnet? It'd have been nice if you quickly showed the previous way of doing Auth in dotnet. Great video bdw.

    • @PatrickGod
      @PatrickGod  ปีที่แล้ว +1

      Hey! Here's the video with JWTs in .NET 7. Hope this helps: th-cam.com/video/UwruwHl3BlU/w-d-xo.htmlsi=v4pXBo-AIGl1tVuf

  • @netrunner1987
    @netrunner1987 ปีที่แล้ว

    So, all of those APIs are ... just part of the packages and no code required?

  • @ragnadrok7
    @ragnadrok7 ปีที่แล้ว

    What is the content of the cookie ? Does it store some session in database ? Its not jwt, what is it ?

  • @heropoterxd5142
    @heropoterxd5142 8 หลายเดือนก่อน

    Thank you Very much for this amazing video

  • @hfpsc27
    @hfpsc27 ปีที่แล้ว

    Thank You! Great, simple, eficient. It would be nice if we could see something like a SSO with other API's and/or a Blazor client. 🙏

  • @benechem897
    @benechem897 ปีที่แล้ว

    I've learned more in a couple minutes than I did in a full semester. Now, what if I want to generate api key in case I want to give other people access to some data without the need of an account?

  • @GraceAnnSalvame
    @GraceAnnSalvame 8 หลายเดือนก่อน

    Thank you. I hope you will make Role-based authorization for .net 8 in a web API

  • @kaushalprkh
    @kaushalprkh 10 หลายเดือนก่อน

    looking for Windows Auth without entityFramework. pls help!