Secure Your .NET API in 15 Minutes: JWT Authentication Tutorial

Поделиться
HTML-код
  • Опубликовано: 5 фев 2025

Комментарии • 87

  • @MilanJovanovicTech
    @MilanJovanovicTech  5 месяцев назад +5

    Do you want to simplify your development process? Grab my free Clean Architecture template here: bit.ly/3Andaly

    • @BeijoVegan
      @BeijoVegan 5 месяцев назад

      Can I make a suggestion? Please, use some kind of editing software that zoom in where you click with the mouse. It's very hard to follow your coding on mobile phones.

  • @19balazs86
    @19balazs86 5 месяцев назад +13

    JWT is a nice topic, and I can not wait for the continuation of Keycloak.

  • @dobjek
    @dobjek 2 месяца назад +1

    Thanks!

  • @pratikpandya2306
    @pratikpandya2306 5 месяцев назад +2

    You sound calm now. It’s great content, Keep it up.

    • @MilanJovanovicTech
      @MilanJovanovicTech  5 месяцев назад +1

      It varies based on how many coffees I had prior ☕☕

  • @shanabunny
    @shanabunny 5 месяцев назад +1

    I was just about to implement it. Perfect timing thank you.

  • @Credi6464
    @Credi6464 5 месяцев назад +2

    Pure gold content! Thanks for that!

  • @EzequielRegaldo
    @EzequielRegaldo 5 месяцев назад +1

    Awesome, your tutorials are the best !

  • @dobjek
    @dobjek 2 месяца назад +1

    Thanks Milan, excellent tutorial as always! Works as a charm out of box. How about next video of token expriration scenario as well as basic roles support? Coffee tips will be provided ;)

    • @MilanJovanovicTech
      @MilanJovanovicTech  2 месяца назад +1

      I'm releasing a video about refresh tokens very soon! And then extending this with some baked in AuthZ support won't be too difficult.

  • @iq4u213
    @iq4u213 5 месяцев назад +2

    Awesome video !
    next video should be about Refresh Token

    • @MilanJovanovicTech
      @MilanJovanovicTech  5 месяцев назад +2

      Good idea, actually!

    • @pierrickmassin7099
      @pierrickmassin7099 6 дней назад

      @@MilanJovanovicTech Hey ! Awesome work !
      Is it still only an idea ? Did you made the video ?

    • @MilanJovanovicTech
      @MilanJovanovicTech  6 дней назад

      @pierrickmassin7099 Yes, watch here: ruclips.net/video/kR_9gRBeRMQ/видео.html

  • @ukgames304d
    @ukgames304d 5 месяцев назад +5

    please Milan make a video about implementing refresh token :)

  • @MarvinKleinMusic
    @MarvinKleinMusic 2 месяца назад +1

    I really wish you would have showed the concept of refresh tokens here as well

  • @vbachris
    @vbachris 5 месяцев назад +7

    2 added bonus material?
    1) token refresh
    2) in conjunction with EntraID

  • @enricoroselino7557
    @enricoroselino7557 5 месяцев назад +1

    great video as always, do you have any tips on implementing role based access control using jwt ? or i shouldnt implement it inside jwt in the first place ?

    • @MilanJovanovicTech
      @MilanJovanovicTech  5 месяцев назад +2

      You can add the roles as claims on the JWT, it's pretty simple. You then use these claims to implement an authorization policy.

  • @isahirzm
    @isahirzm 5 месяцев назад

    Great tutorial, when it comes to consume the API, what would be the best practices to do on the consumer(front-end)

  • @s.a.h.i1261
    @s.a.h.i1261 4 месяца назад

    Would love to see a video on how to protect this system additionally from CSRF attacks

  • @abdullahm.3363
    @abdullahm.3363 5 месяцев назад +1

    Great video, how to create a refresh token, so the user don't have to login again and again.

    • @MilanJovanovicTech
      @MilanJovanovicTech  5 месяцев назад +2

      You can use a similar approach to here. Just store the refresh token in the DB, and give it a longer lifetime. Then expose an endpoint to send the refresh token in exchange for a new access token.

    • @Mo-ef9yt
      @Mo-ef9yt 5 месяцев назад

      Thanks​@@MilanJovanovicTech

  • @asesorwebvideos
    @asesorwebvideos 5 месяцев назад

    gracias saludos desde CHILE

  • @Arshaad786000
    @Arshaad786000 5 месяцев назад

    this is brilliant. can you show us how to implement something like this with microsoft identity and roles

  • @VishalYadav-oq9if
    @VishalYadav-oq9if 5 месяцев назад

    Awesome 👍

  • @davidespada01
    @davidespada01 5 месяцев назад +1

    thank you
    can you show us how to consume the JWT token with validating

    • @MilanJovanovicTech
      @MilanJovanovicTech  5 месяцев назад

      What do you mean by this?

    • @EzequielRegaldo
      @EzequielRegaldo 5 месяцев назад +1

      When you use Auth required in some route its automatically validated. Library does it for you

    • @EzequielRegaldo
      @EzequielRegaldo 5 месяцев назад

      @@MilanJovanovicTech maybe caducation or refreshing

    • @davidespada01
      @davidespada01 5 месяцев назад +1

      @@MilanJovanovicTech sorry i was not clear, i meant if i have an api application that will get jwt from other application and use it for further api calls what if i need to validate that jwt 1st in case it was encrypted
      Thank you ,, your amazing

  • @theeusftn
    @theeusftn 5 месяцев назад

    can you teach how to make hmac authentication?

  • @denisgudiel5574
    @denisgudiel5574 5 месяцев назад

    Is the Manger user secrets more secure than the appsettings?

    • @MilanJovanovicTech
      @MilanJovanovicTech  5 месяцев назад

      I didn't quite understand you there

    • @denisgudiel5574
      @denisgudiel5574 5 месяцев назад

      @@MilanJovanovicTech is that you use the "Manager user secrets" to save the jwt key

  • @omidkianifar5144
    @omidkianifar5144 5 месяцев назад +2

    Continue Keycloak series plz

  • @dhmilmile1
    @dhmilmile1 5 месяцев назад +1

    How can we implement refresh token?

    • @istovall2624
      @istovall2624 5 месяцев назад +3

      Do the same thing bit set the refresh token lifespan to longer then send them both. when the jwt expires resubmit them both to reissue. Still validate the jwt but make sure the only part invalid is the expires. Validate the refresh token. If valid and not expired, reissue new jwt.

    • @MilanJovanovicTech
      @MilanJovanovicTech  5 месяцев назад +2

      There you go 😁

    • @ojhkhofdgfd
      @ojhkhofdgfd 5 месяцев назад +1

      @@MilanJovanovicTech That's a great video! I believe you mentioned it is possible to somehow use the refresh token generated by AddIdentityApiEndpoints Service login endpoint to refresh JWTs?

    • @dhmilmile1
      @dhmilmile1 5 месяцев назад

      @@istovall2624 got it thanks

  • @ALOKSHARMAMD
    @ALOKSHARMAMD 5 месяцев назад

    do you have any videos explaining tools like open telemetry, application insights, grafana etc with dotnet. i have been going through different tools to implement in-app profiler for potential memory leaks handling and its very confusing on what to choose to identify & record basic memory/cpu usage for leaks and exceptions etc. As application insight is Azure specific, and other tools are not so easy to add by top attribute. any suggestions which doesn't rely on cloud deployments?

    • @MilanJovanovicTech
      @MilanJovanovicTech  5 месяцев назад

      Check out the OpenTelemetry video here: ruclips.net/video/HrRrJ5wTtdk/видео.html
      You should be able to use the metrics in Aspire to gain some insights

  • @RicusNortje
    @RicusNortje 5 месяцев назад

    Now you don't even need to pass in the user ID on the get user endpoint as you can get it from the JWT subject

  • @WangAndrew
    @WangAndrew 5 месяцев назад

    how do you validate the jwt token on the client side, if blazor wasm ?

    • @MilanJovanovicTech
      @MilanJovanovicTech  5 месяцев назад

      I believe you'd need the key to verify the hash, which isn't ideal. But if you just want to parse the content, that's not as hard.

    • @WangAndrew
      @WangAndrew 5 месяцев назад

      @@MilanJovanovicTech what if the server side use ‘asymmetric’ then the client side only need the public key not the private key

  • @АлексейАнтонов-ф5ш
    @АлексейАнтонов-ф5ш 5 месяцев назад

    Do something about external signin, like facebook, google, etc.

  • @agusbudianto4473
    @agusbudianto4473 5 месяцев назад

    Hi Milan, how to integrate this JWT token with SignInManager in Identitiy Core

    • @MilanJovanovicTech
      @MilanJovanovicTech  5 месяцев назад

      Use SignInManager to verify password, and then generate a JWT and return it

  • @MahmoudSaed98
    @MahmoudSaed98 3 месяца назад

    Milan please we want a video about Refresh Token

  • @СтасСеверин-н9й
    @СтасСеверин-н9й 5 месяцев назад

    Where can i download this code?

    • @MilanJovanovicTech
      @MilanJovanovicTech  4 месяца назад

      This code on www.patreon.com/milanjovanovic
      But also try this :) www.milanjovanovic.tech/templates/clean-architecture

  • @esdegan7176
    @esdegan7176 2 месяца назад

    how if it got stolen?

    • @MilanJovanovicTech
      @MilanJovanovicTech  2 месяца назад

      You change the signing secret

    • @esdegan7176
      @esdegan7176 2 месяца назад

      @@MilanJovanovicTech with that solution, so if one user got stolen, all user signed outed. which not expected by other user. right?

  • @tumers.1595
    @tumers.1595 4 месяца назад

    Good tutorial. But it seems to write all the codes into memory. It seems unrealistic and insincere to me.

  • @jonchicoine
    @jonchicoine Месяц назад

    This doesn't' work that well as a standalone tutorial. imo For anyone familiar with project solution its probably a 10/10.