ไม่สามารถเล่นวิดีโอนี้
ขออภัยในความไม่สะดวก

Authenticating Web API Using ASP .Net Identity and JSON Web Tokens (JWT)

แชร์
ฝัง
  • เผยแพร่เมื่อ 2 ส.ค. 2024
  • In this video, we talk about how to Authenticate Web API applications using Asp .Net Core Identity and validate the incoming requests using JSON Web Token (JWT).
    Buy me a coffee: buymeacoffee.com/foadalavix
    Patreon: / foadalaviyoutube
    ⏱️VIDEO CHAPTERS⏱️⏱️
    00:00 - Intro
    00:11 - Identity Context
    05:53 - Register User and Login
    21:30 - Add Authentication
    25:17 - JWT Configuration
    29:10 - Generating JSON Web Token
    38:29 - Testing using Postman
    🔔 Subscribe for more tips just like this: www.youtube.com/@Foad_Alavi?s...
    Learn how to implement secure authentication for your ASP.NET Core Web API application using ASP.NET Identity and JSON Web Tokens (JWT).
    In this tutorial, we'll walk through the process of creating an Identity context using Entity Framework Code First, registering users in the database, and logging them in. We'll also show you how to configure your Web API to use JWT for authentication and demonstrate how to generate a token for JWT.
    Follow along as we test our application using Postman.
    By the end of this video, you'll have a solid understanding of how to authenticate Web API using ASP.NET Identity and JSON Web Tokens.
    GitHubRepo: github.com/foadalavi/ASP.NET
    ASP.Net Core Playlist: • ASP.Net Core
    #csharp #dotnet #aspdotnetcore #webapi #identity #jwt

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

  • @user-wl4wm8xg7c
    @user-wl4wm8xg7c ปีที่แล้ว +1

    Actually one of the best guides on Identity and Jwt! Thank you so much.

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

    Keep up the great work. Well done!

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

    The best person who displayed this section 🙏🏻
    Go ahead man 👍🏻

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

    This explanation of JWT and Identity is the best I've found! It's really clear and easy to understand.

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

      Glad you think so!

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

    You're awesome, man! This is just what i needed. You helped me a lot with this tutorial!!! Keep going :)

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

      Glad I could help!

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

    nice keep it up

  • @karlpjd
    @karlpjd 8 วันที่ผ่านมา

    Loved this video, really insightful compared to watching someone copy and paste code ..

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

    I'm from Shiraz, and I'm so grateful for your helpful content. It's been a pleasure learning from you.

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

      Thanks. The pleasure is mine to share my knowledge with my compatriots.
      I have been to Shiraz once, and it is one of my best memories.

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

    Excellent Content, and valuable tips, as always; thanks for sharing.

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

      Thanks for watching it.

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

    Amazing video and clear explanation about the topic. New suscriber from Argentina!

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

      Welcome aboard!

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

    Super 👏

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

    just Awesome

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

    best one yet

  • @parkhieu4757
    @parkhieu4757 25 วันที่ผ่านมา

    Thank you for tutorial

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

    Excellent tutorial, Thank you so much.

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

      You are welcome!

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

    Senior Developer indeed. You are just awesome. You know the flow. If I stay with you for 2month my programming life cannot be the same. You know exactly what you are doing. You know it should work and if it does not work you know why it refuse to work. You are a great Boss and I cut cap for you.

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

      I'm sorry for not getting back to you sooner. I was busy with house renovation and got ill after that.
      Thanks for the nice words. I will upload more and more videos; hope you enjoy them.

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

      @@Foad_Alavi No problem boss.
      Sorry about that sir. I just believe you're strong now.
      Can't wait for more of your videos. You've made me addicted to this challenge already and I really thou love it.

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

    Excellent tutorial and thanks for the code too!

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

      You're welcome!

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

    That you have provided such wonderful content, kindly implement role-based authentication.

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

      Sure. It is planned.

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

    thank you so much for uploading such quality content.

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

      Glad you enjoy it!

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

    Thank you sir from Turkey

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

      You are welcome!

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

    Excellent...Thanks a lot🎯

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

      You’re most welcome.
      Do not miss my next two videos in this series. I explained how to use authorization to check permissions.
      I hope you like them both as well.

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

    Great, keep it up 👍

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

      Thank you

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

    Thank you so much, you make such a difficult concept to implement very simple. I appreciate it

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

      I just had a question regarding adding an employee model with its own set of fields and allow for authentication of that user. (Since it's separate from the Users table generated by the Identity package)

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

      Usually, the identity context is isolated.
      I just wanted to demonstrate that we have some other entities there as well. Sometimes, you need to have some other entities or maybe some fields in the user, claim, and roll tables. In the coming videos, about roll and clam-based authorization, I am going to explain it in more detail
      Thanks for watching my videos and asking the question

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

    thank you

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

      You're welcome

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

    best

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

    This was an amazing video. Exactly what I needed for my project, and you do such a great job of explaining what you're doing as you're doing it. Do you have a Paypal or some other way I could send you a tip for this?

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

      Hi,
      I am glad that you liked it and thanks for the nice offer. The best tip for me is to share my channel with other developers. BTW I have five videos about authentication and Authorization, and in the last 2, I explained how I Authorize requests in my projects. You might like them as well.

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

    Can’t we send these access tokens as cookies?

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

    ty ..!!! i am find a guides for implement in my job

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

      I’m glad that you liked it.
      You can check the next two videos of the service I explained about implementing permission check and authorization.
      If you like this video, please share my channel.

  • @b.official
    @b.official 2 หลายเดือนก่อน

    "Could you please explain what the Employee model is used for? I only noticed its presence in the instructional video."

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

    Hello . I will use asp. net mvc and web api in my project. I need to display the user who is currently online in some views in MVC. After making these settings in the program cs file of the API, would it be enough if I download the identity package to the MVC project?

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

      showing the online users is a bit tricky.
      You need to send requests to the server from the clientside every second and notify the server that the user is online
      Mainly do it using a javascript timer on the clientside.
      Please consider the performance overhead that it will have on your project.

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

    Great video, are you planning one version using azure ad as a jwt provider? Would be great if you make this version. God bless you.

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

      Great suggestion!
      I will make one soon.

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

    There are some things I would improve:
    - Your endpoints are not restful... you shouldn't be using actions as endpoints (as /register or /login). a good restful endpoint would be for example POST /auth and GET /auth
    - The results for your endpoints should return "Bad Request" only when it's really a bad request... an incorrect login should return 403 Forbidden

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

      hi, how would you name endpoints for with functionality such as forgot-password, reset-password and account lock/unlock?

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

      @@ondrejdlesk9352 [HttpPost("Login")] OR [HttpPost("Register")].

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

    What about refreshTokens? How'd I handle those, in regards of invalidation?

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

      I have a video about refresh token

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

    How would I use http only cookie to store the jwt ? and use the jwt from cookie ?

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

      Coocke and JWT are 2 different ways of storing the data for authentication on the client side.
      My advice is to keep them separate.
      Could you elaborate more about why you have this requirement?

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

    I see many WEB API / JWT tutorials but I struggle tying the API JWT together with the user logging in on a web page and using the same token to limit the web front end.
    Do you have any videos tying these together?

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

      I have recorded another video about identity and authorization. You should find what you asked for there.
      I need to edit the video first and will publish it by the end of the week.

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

      @@Foad_Alavi i look forward to that, but does it use jwt bearer?

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

      @@jesperkped It does

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

    i have a question if i have a service that i do register and login in there exactly like you said (in Micro services) now how can i use this for other services???

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

      First, sorry for the late response. I was busy with house renovation and got ill after that.
      You can use encryption techniques like SHA that let you have a Public and Private Key to share them between the login Service(application) and other services(application).
      I will make a video about it soon.

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

      @@Foad_Alavi tnx

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

    Can I use it like and endpoint to my React app? I can´t do it

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

      Sure,, you'll be able to do it. Just add the authentication key to the request header.
      Like this:
      key=Authorization, value= "Bearer Token"

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

      @@Foad_Alavi I do it and it’s working, thanks a lot!!!

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

    Is this something a junior developer should be able to do? Got a hard time estimating at what level stuff is sometimes..

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

      This video is for the Midior level, if you have an issue understanding this one, I highly recommend watching my "ASP.NET Core 7 Authentication and Authorization" playlist

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

    Nice, but is this the only way to do authentication and authentication in a web api? How about cookie based authentication or another method asides jwt

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

      We have some more ways to do it, I have a playlist about it containing 5 videos about them, and I suggest you watch them.
      There I explained cookie-based authentication in detail.

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

    but my package like this Package Reference Include="Microsoft. Entity Framework Core. Tools" Version="6.0.16"

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

      Hi Jaya,
      i’m not sure if I got your question correctly or not or even if it is a question or not😉
      Depending on the target framework that you have, do you need to select the correct entity framework version.

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

    The explanation is great but , I guess this Identity library for this version is deprecated. am I wrong???

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

      First thanks for watching the video.
      You might have a valid point, I prepared this project for one of the workshops that I gave based on .net 5, some years ago and I used exactly the same code for this video.
      I will check it and if some libraries are deprecated I will update GitHub repository
      And check my other videos about refresh token and how to use other encryptions like RSA for validating JWT.

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

      Pleasure watching your videos Foad. Mine, was just a reminder. I was not even very much sure. Keep going.@@Foad_Alavi

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

      Use "Microsoft.AspNetCore.Authentication.JwtBearer" instead.

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

    Can anyone tell me what is the language used in this video?

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

      The language that I tried to speak in this video is English😂😂
      The programming language that I used is C# dotnet.

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

      @@Foad_Alavi Oh Great I haven't ever seen C# syntax So I thought it as Java That's why I posted a comment 😅
      But Anyways Thank you @Food Alavi for responding to my comment
      Most TH-camrs won't do such things🔥🔥

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

    35:00 and 36:00

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

      I dont get it. Can you elaborate?

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

    Bro atleast explain sometimes what you are writing, why in so much hurry.

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

    This helped out a ton with my project. Thanks a ton

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

      Glad it helped!

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

    Is it .NET 6 or 7 or even 8? Please, specify

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

      I'm sorry for not getting back to you sooner. I was busy with house renovation and got ill after that.
      The concept in this video is the same as in .NET 6,7 and 8.

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

      Thank you, keep it up ❤️