Implementing JWT Authentication in ASP.NET Core

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

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

  • @mynameisshadywhat
    @mynameisshadywhat หลายเดือนก่อน +31

    The first time in a long time I needed a refresher on this and this is the first recommended video, posted only 17 minutes ago. What sorcery is this, Nick?

    • @nickchapsas
      @nickchapsas  หลายเดือนก่อน +43

      I’m behind you

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

      (⊙ˍ⊙)

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

      it's called youtube algorythem *smirk*

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

      ​@@nickchapsasDo you have a course on sql for ef core developers?

    • @vornamenachname906
      @vornamenachname906 16 วันที่ผ่านมา

      That's called a kind of P-hacking.
      You internally calculate "wow how low was the chance, that this specific channel releases a video about this topic now"
      But in reality you have many channels and probably many queries/demands. The chance that one of them by one of them is fullfilled is much higher.

  • @AJIexa8
    @AJIexa8 หลายเดือนก่อน +21

    Great video! I would suggest to people who are new to JWT first learn fundamentals about OpenID Connect and authorization methods like "Authorization Code Flow" or " Resource Owner Password Grant Flow". Once you understand the flow you will get that Cognito, IdentityServer4 or any other providers are just wrappers around this protocol

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

      I wouldn't recommend IdentityServer4 since it's no longer maintained. Instead use Duende IdentityServer (commercial) or OpenIddict.

    • @hero3616
      @hero3616 24 วันที่ผ่านมา +1

      ROPC flow is obsolete and it should not be used unless your api and STS are on the same server

  • @PhantomPhobos
    @PhantomPhobos 29 วันที่ผ่านมา +9

    Wish to see more on this topic, I started off by rolling own ID server using OpenIddict, was quite a rough start first time learning in the whole OpenID process 😅. Video on rolling your own ID server would be nice, even better if it's using OpenIddict. Still waiting for more videos on event sourcing too, only see one in your channel, perhaps those are locked behind patreon?

  • @EduardLlull
    @EduardLlull 29 วันที่ผ่านมา +2

    I think you should comment that once you start using AWS Incognito service, you don't need the "token generator API" anymore. In my experience, most developers brains shortcircuit when they try to understand oidc and some may think they still need the API even after they start using Incognito because they don't understand how it works.

  • @conniedecinko9245
    @conniedecinko9245 28 วันที่ผ่านมา +4

    We're using Keycloak for both Java and .NET apps

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

    The modern way to create JWTs is using the new `JsonWebTokenHandler` class, not the older & slower `JwtSecurityTokenHandler` class.

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

      You are right. I used my old codebase for this video instead of the new one that used the WebToken one 🤦

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

    It's good starting video on using an external Idp, but don't forget that what's shown here is the bare minimum. Also, notice that Nick is using a stand-alone UI (i.e. Postman or similar) to exchange the returned auth code for a set of tokens that's stored locally (Redis is a great option for these types of short lived data); you'll need to build the exchange mechanism yourself, which is a fun little task.
    A word of caution: security is not something you should take lightly, especially in an public facing environment and you should never attemt to implement encryption algorithms, unless you're one of the very few experts in the industry, that works professionally on this topic.

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

      so pro-apprentices like me probably still better use Auth0?

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

      @@aracon9721 not only you, but almost everyone, except if you work in that Cognito team. as I've heard - never write your own logging and auth.

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

    2:30 "It's a piece of string!"😄love it

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

    It would be awesome if you could show how to support multiple authentication methods. Like an API key together with jwt tokens. How do we correctly authorize endpoints and setup the auth ?

  • @Paps526
    @Paps526 29 วันที่ผ่านมา +1

    Funny thing is that I made exact same implementation with keycloak yesterday for the first time

  • @justinassakalavicius4465
    @justinassakalavicius4465 29 วันที่ผ่านมา

    Great video! I would like to hear more about the other option you mentioned in your video. Server-side applications with confidential clients

  • @tomtoups
    @tomtoups หลายเดือนก่อน +13

    Changing the first letter "e" is not a good test for if the JWT is working, because the "e" is the base64 character for the open brace "{" for the JSON. That's why all JWTs start with an "e". It could be failing because it's not a valid JSON fragment

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

      They all start with "ey". It's like the Matrix, you start to see the code and recognize it if you look long enough.

    • @hero3616
      @hero3616 24 วันที่ผ่านมา

      I don’t think author knows details

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

      You can always decode a base64 string. Nothing is secret about that. The point of changing the content of the token payload was to show that as soon as the payload is changed, the token is invalid because the content no longer matches the signature verification.

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

    Thanks, couple questions tho:
    How should I sync the users to my db with external id providers?
    Should I store roles, permission in my db or in the external provider?
    and also shouldnt client secret be secret? I shouldnt use it in a spa, right?

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

    I'd like to see something simular also showcasing the approach via azure (if possible not sure). And maybe also with something more restrictive configuration(if possible of course), like enabling google or facebook login, where you can customize which google emails can register but , restricted to a specific domain. Or for the facebook side enabling registration for specific users(ofcourse if possible).
    Otherwise again a nice lecture, i enjoy your videos, keep it up👍

    • @hero3616
      @hero3616 24 วันที่ผ่านมา

      It’s called B2C in Azure and free up to 50K users

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

    I much prefer jwt.ms over Auth0's decoder. Much simpler page and also decodes the iat and exp values etc.

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

    @nickchapsas Great refresher. I find it difficult to establish a resources that outlines at length the ins and outs of security(providers, users, flows, scopes, policies, federation). As part of the courses offered on Dometrain do you have a plan to do a comprehensive course on the subject.

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

    It would be pretty intersting how you can secure a Blazor app with JWT.

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

      Same way as the API example in the video. The authorization feature for a blazor component is decoupled from the authorization method. For example, for a product I made a blazor app authorizing users with OpenID through Azure AD but the components themselves has no idea HOW the user is authorized. They just allow access IF the user is autenticated and - in some case - is authorized with certain roles. In this case the OpenId could easily be replaced with a simple login using JWT without changing anything in the blazor components.

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

    This couldn't of come at a better time.

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

    Hey Nick, can you make a video about which is the nicest butter?

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

      Let's demand a #buttercop series in which Nick takes a look at terrible butter advice posted on LinkedIn and signs off with "But now I want to know about you.... which butter do YOU think is the nicest butter? Are you using butter in your applications? Or a healthy low-fat substitute?"

  • @LilPozzer
    @LilPozzer 22 วันที่ผ่านมา

    These Boots Have Seen Everything

  • @hristoivanov6436
    @hristoivanov6436 5 วันที่ผ่านมา

    Nice video! Could you show us S2S auth process?

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

    When i see you doing it seems graspable
    Why everyone else claims that authentication and authorization are the holy grail of programming? Concepts so difficult to grasp that you need a doctorate degree!?

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

      It's poorly documented in certain areas, and I've found most of the answers digging through stack overflow. Concepts aren't that difficult, but implementation in .NET can be a she-dog...

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

      I never saw anybody saying it is "the holy grail of programming", but it is a difficult problem, yeah.

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

      Because the hard work is being done for us by people that know a lot more about it than we do. It's effectively lego-by-design specifically because it's so hard to get right.

  • @SILASGAH
    @SILASGAH 29 วันที่ผ่านมา +1

    Not sure if I am the only one or not, kindly take your time when talking, you seems to be extremely fast when talking. You are educating us

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

    Have you ever considered or compared this to something opensource and self hosted like key cloak? I've used it in a couple of project and i has pretty much all you've showcased but it's bit more quirky.

    • @PelFox
      @PelFox 29 วันที่ผ่านมา

      Keycloak follows the oidc/oauth2 protocol and comes with lots of identity providers, user management and roles. It's a complete solution compared to this example which just creates a JWT token from hardcoded values.

  • @vasilyh4588
    @vasilyh4588 29 วันที่ผ่านมา +2

    What about roles check during API call?

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

    Nick which SO do you use?

  • @SuperAndrea000000
    @SuperAndrea000000 23 วันที่ผ่านมา +1

    It would be awesome if you could make a video about how to implement a refresh token mechanism in my API project.
    My API issues a JWT with a refresh token, but when the browser makes multiple requests in parallel, sometimes they fail because the first one refreshes the JWT, while the others fail because the refresh token has already been used. It would be nice to see how you'd solve this problem.

    • @hck1bloodday
      @hck1bloodday 22 วันที่ผ่านมา

      may be implement a retry mechanism on the frontend?

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

    Ok, this bg3 reference got u one more like. Are you happy now???

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

      What an absolute banger of a game

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

    "Trust me" Famous last words :) But in all seriousness, could you use something like this to authenticate your application? Basically making it not possible for anyone outside of your hosted domain to request data from the API?

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

      CORS is better suited for that. You can set it up a policy on your server to say “If a request comes from anywhere other than a specific URL, reject it”, and then give it the URL of your client application so that only requests from your client application are let through.

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

      @@DisturbedNeo From what I understand about CORS is that it cannot be used to authenticate your application. CORS being only relevant within a browsers JavaScript, they read the CORS headers from the response and raise the error if the URL doesn't match the one in your address bar. Anyone can still make a request and get a response with curl or any other API tool.

    • @hero3616
      @hero3616 24 วันที่ผ่านมา

      @@DisturbedNeocors has nothing to do with server side

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

    What do you mean "Production Ready"? I already implemented JWT to PROD using knowledge from your previous video about JWT!
    o_0

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

      Maybe production ready isn't a good term for this. I wanted to say that we're integrating an independent identity service which is what most modern production apps are using. Maybe "Modern" is better

  • @ezekielgallardo8385
    @ezekielgallardo8385 16 วันที่ผ่านมา

    Can you show an example of this using Active Directory?

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

    What about the user in DB?
    Manage additional data ?
    That you don’t want to exposed in jwt
    How you will merge the auth flow with real application need like current user in a request context
    Gather additional info from db and so on
    In best practice from your perspective

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

    cool. could you show us how this would work with the microsoft identity tables in SQL

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

    Does .dometrain have any support? What is the problem with the video player?

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

    definitely make a video for service/machine/server authentication. duh! uh, i mean please :)

  • @TheCodeCreator
    @TheCodeCreator 29 วันที่ผ่านมา

    Can JWT also be used in simple ASP NET Core webapps (no API's), right? Thanks.

  • @chrisstephens2694
    @chrisstephens2694 20 วันที่ผ่านมา

    A really clear and concise explanation, as usual! It would be good to see something similar but utilising Entra Id rather than AWS Cognito.

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

    Any chance of making a video for integration with MS Entra SSO?

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

    Is there a way to add users to the cognito service (rather than users having to enrol)?

    • @mibli2935
      @mibli2935 26 วันที่ผ่านมา

      Yes. (If I understood your question correctly). Login to your AWS, find Cognito Service, create your UserPool and in the tab "Users" you can do just that.

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

    Who else felt odd when Nick wrote just 60?

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

      Don't think when making an advert video he could do 69.

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

    I don’t know what other people feel about your way of speaking but I feel tired after listening you for 5 minutes. In my opinion quality doesn’t mean 100 words per minute. In the past your explanations were more human than now. Hope you understand my feedback.

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

    My gosh, you use so many words to convey so little information.

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

    You’re not explaining what anything means, you’re effectively showing how to copy paste your code

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

      There are 500000 videos explaining JWT including mine. Watch those. I just wanna show the implementation

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

      You're missing the point of the video if you're expecting a dive in to how JWT works

    • @Paps526
      @Paps526 29 วันที่ผ่านมา

      @@nickchapsas I would explain what's MetadataAddress, this has a key role I think in this approach

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

    Azure AD (Entra) B2C is way better than Cognito

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

    Hi, NIck, coud you make video about ocelot api gateway with Scalar.AspNetCore

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

      I'd suggest using YARP instead..

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

      @@VanDameDev does YARP can be integrated with scalar for centralize API docs?

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

      @@sachinmaharjan6398 If you do include scalar in the ApiGateway(YARP) project, I don't see why not..

  • @vornamenachname906
    @vornamenachname906 16 วันที่ผ่านมา

    Im really wonder why you repeatingly confuse classes and functions , e.g. 3:16 and also in other videos

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

    ".NET does not have native JWT integration, so you have to install a Nuget package..." is said like it is a negative thing, but it is a positive one. Why would the core library have support for a specific auth mechanism, of the hundreds that have come and gone?

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

      It’s not said as a negative thing. It’s said as an observation

    • @Otto-the-Autopilot
      @Otto-the-Autopilot หลายเดือนก่อน

      Also the package is still from Microsoft themselves, thus you don't have to rely on some 3rd party library.

  • @rohitm8814
    @rohitm8814 24 วันที่ผ่านมา

    too fast man!!!

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

    var key="sdfafas"u8; just to learn this notation was worth watching the video 🙂