How to use JWT with RSA key-pair in micro-services. (JWKS.JSON)

Поделиться
HTML-код
  • Опубликовано: 6 июл 2021
  • #JWT
    In this video you will learn how to use #RSA #private-public key-pair to be used as a secret inside your JWT. Instead of using symmetric key to sign and verify the jwt's, we will be using asymmetric algorithm to sign and verify the jwt. Private key would be used to sign a JWT and the public key would be used to verify the signature of the JWT. The tutorial is based upon the #RFC7517 standard using Json Web Keys. You would be learning how to provide the public key to other micro services using something called a (#JWKS) Json Web Key Sets (#jwks.json).
    It's something that is also used by #Auth0, the identity management provider, they use the same logic for client side verification of the #Access tokens.
    --------------------------------------------------------------------------
    ⭐ Kite is a free AI-powered coding assistant that will help you code faster and smarter. The Kite plugin integrates with all the top editors and IDEs to give you smart completions and documentation while you’re typing. I've been using Kite for 6 months and I love it! www.kite.com/get-kite/?...
    --------------------------------------------------------------------------
    📦FREE $100 credit @Digital Ocean: m.do.co/c/3208f08b3324
    Subscribe: ruclips.net/user/yourstruly2...
    --------------------------------------------------------------------------
    💵Support the channel:
    Paypal: www.paypal.me/trulymittal
    Patreon: / trulymittal
    --------------------------------------------------------------------------
    🚀Deploy apps: zeet.co/r/yourstruly
    (One FREE project forever 😘)
    --------------------------------------------------------------------------
    Packages used:
    express-draft: www.npmjs.com/package/express...
    jsonwebtoken: www.npmjs.com/package/jsonweb...
    rsa-pem-to-jwk: www.npmjs.com/package/rsa-pem...
    express-jtw: www.npmjs.com/package/express...
    jwks-rsa: www.npmjs.com/package/jwks-rsa
    RFC7517 datatracker.ietf.org/doc/html...
    ======================
    ✔ Other useful Playlists
    ======================
    #RestAPI (#NodeJS and MongoDB): • REST API using NodeJS ...
    #API Authentication using #JWT: • NodeJS API Authenticat...
    Firebase: • Firebase | Build a Not...
    Docker: • Docker
    MongoDB: • Learn MongoDB in 50 mi...
    Html/Css/Js: • HTML / CSS / JS
    Android: • Android
    Challenges: • Challenges
    #yoursTRULY #tutorial #howto #nodejs

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

  • @KrishnaJha25
    @KrishnaJha25 2 года назад +26

    Let's take a moment and appreciate the work you are doing. Honestly, people would charge hundreds of dollars if not thousands for these kind of videos. Very practical and to the point. Amazing explanation. I recently found your channel and believe me the content I'm finding here is exactly what I needed.
    Thanks man. Thank you so much for making such helpfull videos for us.

    • @mafiacodes
      @mafiacodes  2 года назад +2

      I m glad that you like, comment like this motivates me in bringing more videos like this, thank you, subscribe like share 🙏

  • @be_b_50_ankitkumar_singh79
    @be_b_50_ankitkumar_singh79 3 года назад +9

    This is the place where real software engineers come to worship :) Thanks for these videos. Practical implementation is much required, you are filling the gap very well :)

  • @vinodt.r.9124
    @vinodt.r.9124 2 года назад +5

    I share the sentiment as many other folks who have commented here. I went through many videos to get a simple explanation to JWKS and none was as perfect and simple as your explanation. Crisp explanation. Not too fast, not too slow. Keep coming up with more videos.

    • @mafiacodes
      @mafiacodes  2 года назад

      Thanks for that!
      Subscribe like share

  • @cuchitp
    @cuchitp 3 года назад +1

    I have only just found out your channel, and I really enjoy them! Thank you 😊!
    I’m going to search your video library to check some more!

  • @kgck15
    @kgck15 2 года назад +5

    This is excellent video. Exactly what I needed!

  • @dmitrydovgopol8724
    @dmitrydovgopol8724 2 года назад

    A huge thanks for this video! Great flow of the explanation!!!

  • @Alex-fj2xu
    @Alex-fj2xu 2 года назад +2

    Plain and simple! Keep going, please.

  • @WebDevdai
    @WebDevdai 3 года назад

    Welcome back buddy!!, thanks

  • @aryanvikash1967
    @aryanvikash1967 2 года назад +1

    Man whenever I dig your channel I found something new ❤️

  • @gibraanjafar1669
    @gibraanjafar1669 3 года назад +2

    where have you been amigo ? Have been missing these videos. Great to have you back !

    • @mafiacodes
      @mafiacodes  3 года назад +1

      I’ll try to be regular every week

  • @ajk7151
    @ajk7151 Год назад +1

    simply awesome tutorial. crisp & concise! was stuck because of jwks issues. thanks a lot for this. :)

  • @subhashgn1775
    @subhashgn1775 2 года назад +1

    Loved your explanation.
    👏👌👌
    Thank you for this great resource.
    Very grateful to you

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

    Beautiful.
    Clear and Crisp.
    Love it

  • @rahulg8872
    @rahulg8872 3 года назад

    Welcome back buddy!!

  • @madhawawijekoon1204
    @madhawawijekoon1204 2 года назад

    Superb explanation and giving really good understanding to the securing API end points in microservice architecture using JWT. very practical!, thank you.

  • @rajmiglani4159
    @rajmiglani4159 2 года назад

    Sinclearly explained 👍, got here from Google news on early mornings

  • @prakashapec1
    @prakashapec1 2 года назад

    good explanation..!! you have covered a lot in this one video. Thanks for sharing your knowledge.

  • @DigitalWinner
    @DigitalWinner Год назад +1

    Awesome! Thanks

  • @basias5867
    @basias5867 Год назад +1

    Very good content, very well explained, amazing stuff.

  • @MajidMahdaviNasr
    @MajidMahdaviNasr 2 года назад

    Thank you for this Great video.

  • @ahmedbathily7013
    @ahmedbathily7013 2 года назад +3

    This is another level your are very Amazing

  • @pandulaweerasooriya7689
    @pandulaweerasooriya7689 2 года назад

    This is simply brilliant

  • @arnabsahoo2251
    @arnabsahoo2251 3 года назад

    Welcome back, man.🎉🎉
    Make a series on microservice application design in nodejs.

  • @TechPuzzle_Haven
    @TechPuzzle_Haven 3 года назад

    Great video.

  • @surendrareddyseelam9757
    @surendrareddyseelam9757 3 года назад

    Master is back

  • @zohaibshahzad4567
    @zohaibshahzad4567 2 года назад +1

    You deserve love

  • @zoltancaputo9562
    @zoltancaputo9562 11 месяцев назад +1

    tks for sharing ... amazing teacher!

    • @mafiacodes
      @mafiacodes  10 месяцев назад

      Glad you liked it!

  • @rvndnishad
    @rvndnishad 3 года назад

    Welcome back ...

  • @sfincione2000
    @sfincione2000 11 месяцев назад +1

    Really good explanation and example. Nice job

    • @mafiacodes
      @mafiacodes  10 месяцев назад

      Glad you liked it!

  • @tanmaypatra9455
    @tanmaypatra9455 2 года назад

    Informative with demo

  • @PROTECHRAHUL
    @PROTECHRAHUL 8 месяцев назад +1

    Accurate ❤❤

  • @muratasarslan2359
    @muratasarslan2359 Год назад +1

    Very well, thank you for your efforts 🙂

  • @daoudadione7479
    @daoudadione7479 Год назад +1

    Thaaaank's

  • @_ityadi
    @_ityadi 2 года назад

    I just subscribed. Great video. Very well explained with proper code walkthrough. May I know which IDE you are using and which theme. The IDE color coding looks very cool.

  •  2 года назад

    Thanks!

  • @sudeepkotari
    @sudeepkotari 3 года назад

    Waiting for your next video on node js Micro services

  • @patrickconrad2874
    @patrickconrad2874 2 года назад

    Dude this is an amazing tutorial. Thank you. Quick question for you or anyone. What's the best way to include multiple keys? I have a few different keys on my auth service, for like email verification, resets, two-point auth. Do the keys need to have a name associated with them at that point? Also is there any reason I can't store the key sets in a db? not for my own auth purposes, but I am building an oauth type system so I don't have to keep remaking the front-end logic for all the auth routes, and to offer to use it for my clients' sites as well. So what I have now is I generate keys using crypto, and then save them to an organization model. is that for any reason a security flaw? any suggestions on what I should do instead if there are security concerns.

  • @shahreazneeloy2119
    @shahreazneeloy2119 Год назад

    Very amazing video. Please make a video on jose npm package

    • @mafiacodes
      @mafiacodes  Год назад +1

      Bro it’s the same with more features, you can use that as well

  • @ismailsanane268
    @ismailsanane268 2 года назад

    Great piece of work. Just a tiny correction for 2:06 . You should say "symmetric", not "asymmetric "

  • @lonesareer
    @lonesareer 11 месяцев назад

    Thanks for the great tutorial . I have one doubt. You said jwks is the representation of public key but you passed the private key to convert into Jwks

  • @neerajverma9226
    @neerajverma9226 3 года назад

    You should start tutorials for Spring boot

  • @ramandahiya6977
    @ramandahiya6977 7 месяцев назад

    ❤❤❤

  • @riteshthakur9250
    @riteshthakur9250 3 года назад

    And please make a video on how to deploy node microservice on aws or any other

  • @SH.K_
    @SH.K_ Год назад

    🧡

  • @mukuljain8383
    @mukuljain8383 3 года назад +1

    Make videos please we need you make more videos on backend and front end

  • @patcodingcodester9781
    @patcodingcodester9781 3 года назад

    Is there a reason I can't just use environment variables and a db instead of doing all of the work with pem files? My system is set up so a secret is generated for each user and that is then stored as their own secret environment variable. On requests to my auth server it uses that environment variable to set a cookie, and my authserver verifys the jwt in the cookie to the db vs a json file. But isn't it all the same thing basically? Or is doing it this way worth the change in the code. Also it's a lot of dependencies this way and that always worries me.

  • @milon27
    @milon27 3 года назад

    How can we use jwt for authentication for rest API mitigating XXS & CSRF attack?

  • @sirnawaz
    @sirnawaz 2 года назад

    At 19:50, you should have explained why you're using "RS265", why not "RS384"? I understand these are not related to the keys that you generated. However, the questions about the choices that you made still confusing to some of us.. as to why you did not use X and used XX instead when they look almost similar. Overall, excellent tutorial though. 😃

  • @napoleonbonaparte1260
    @napoleonbonaparte1260 2 года назад

    hello I have a question, do you recommend to create your own authentication and authorization instead of outsourcing it? or get a library instead? if not what libraries or paid services do you recommend to use in medium scale to large scale application? thank you.

    • @mafiacodes
      @mafiacodes  2 года назад +2

      1. outsourcing? Depends on the project size, if small then definitely yes, example (firebase auth, auth0, magic links, etc, you can use any everyone has their advantages)
      2. Library? One thing more you can definitely use libraries like - passport, next-auth for next's, etc.
      3. If you have a large project, you should OWN your authentication system, otherwise you will be charged a lot in longer run, but that also means that what you are coding for authentication, and it should be rock solid, and only do that if you know what you are doing, otherwise use an authentication service as above.

  • @hackingguy
    @hackingguy 3 года назад

    Can u please make a series on design patterns, like DDD, TDD, SOLID etc, (Clean Code)
    It is not available on RUclips for NodeJS, please check this out!

  • @gokul7857
    @gokul7857 Год назад

    Whether this flow is same as OAuth 2.0 Client Credentials Flow...Can you please check and tell?

  • @abhinavadarsh7150
    @abhinavadarsh7150 3 года назад +1

    In a authentication system, we have two tokens - refreshToken and accessToken. accessToken is needed to be verified on every microservices so, we definetly use public and private key pair for it. But the refreshToken is used to verify only on the auth service to return a access token. So, do we use public and private key pair of the refreshToken also or stick with secrets.

    • @mafiacodes
      @mafiacodes  3 года назад +1

      Exactly you are correct, you can easily use secrets for refresh tokens, only access tokens need pub/priv key

    • @abhinavadarsh7150
      @abhinavadarsh7150 3 года назад

      @@mafiacodes Thanks!

    • @abhinavadarsh7150
      @abhinavadarsh7150 2 года назад

      @@mafiacodesIf we have secret then we use env vars. But here we cannot push the cert folder to github or set them as env vars. So, how to handle deployment with public key and private key.

  • @mahimahesh5616
    @mahimahesh5616 3 года назад

    How to setup authentication for mongodb in kubernetes

  • @lytuan5836
    @lytuan5836 2 года назад +1

    I have a confuse, when you publish a jwk.json then attackers also be able to get it and use the man-in-the-middle attack method to decode, verify and change some information? can you explain it for me??? thanks advanced!

    • @mafiacodes
      @mafiacodes  2 года назад +1

      Only public key is exposed, and in an asymmetric algorithm like RSA, public key is publishable and it is no harm because public key is meant for public, moreover one can only verify the authenticity of the token with this key, he will not be able to modify the token in any way, incase if he does modify the token would not be valid when verified with a public key.

    • @lytuan5836
      @lytuan5836 2 года назад

      I got it, thank you so much!

  • @azharponani
    @azharponani 3 года назад

    Hi sir,
    Can you please tell me the zsh mod you are using? Your terminal looks beautiful
    Thank you

  • @beratdinckan5585
    @beratdinckan5585 2 года назад

    how can I use this method with nginx?

  • @fikreteliyev2266
    @fikreteliyev2266 7 месяцев назад

    Please
    You will write this way for express rest api

  • @saimanish3385
    @saimanish3385 3 года назад

    If both auth and resource modules are in same project, can we use directly public key to verify jwt

  • @harshaldeshpande8393
    @harshaldeshpande8393 2 года назад

    Can we store the keys for RSA in .env files?
    Should we include or exclude .pem files while pushing to remote git repo and deployment??

    • @mafiacodes
      @mafiacodes  2 года назад

      you can use your rsa PUBLIC (ONLY PUBLIC) wherever you want, and just keep the private key safely locked...

    • @usmansuleiman7998
      @usmansuleiman7998 2 года назад

      @@mafiacodes where can we store it for a Docker application?

  • @vishalshah8626
    @vishalshah8626 Год назад

    I echo Krishna Jha

  • @easwarapriyan9763
    @easwarapriyan9763 Год назад

    Getting undefined when passed pem files to rsaPemToJwk() function...
    Any one can help me ?
    Note:the pem files is readed properly and import also done property...

    • @glitch0753
      @glitch0753 Год назад

      Getting same error here! @yoursTRULY267

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

      const b = Buffer.from(privateKey, "utf-8");
      let cert = b.toString();
      let certString = cert + "
      ";
      const jwk = rsaPemToJwk(certString, { use: "sig" }, "public");
      console.log(jwk);

  • @azzedinezouba940
    @azzedinezouba940 3 года назад

    Hello my dear brother, can I ask for help in decrypting the data of a game I want to modify

  • @kifkifa56
    @kifkifa56 3 года назад

    Where to store the token???

    • @UmaDevi-lg9bu
      @UmaDevi-lg9bu 3 года назад +1

      use either httpsOnly cookies or authorised headers

  • @jamshidbekabdullayev7439
    @jamshidbekabdullayev7439 2 года назад +1

    Good night! Why such a result is returning?:
    node convertPemToJWK.js
    undefined
    Please, help me!