Tutorial: How to add security to a REST API using JWT Authorizers and Amazon Cognito | JWT Token

แชร์
ฝัง
  • เผยแพร่เมื่อ 20 ส.ค. 2024
  • A quick tutorial on how to secure your AWS REST APIs using AWS Cognito, JWT Tokens, and JWT Authorizers. We will have the API Gateway setup with JWT Authorizers that will verify each api request has a valid JWT Token. These tokens will be generated from AWS Cognito for an authenticated user.
    Topics covered:
    1) Simple Lambda Creation using Nodejs
    2) Cognito User Pool Creation
    3) API Gateway Authorizer - JWT Authorizer

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

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

    Straightforward and awesome video

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

      I am glad you found it helpful. I do plan on making more, just need to find the time.

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

    Thanks a lot! Very concise and to the point! 👌

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

    Great video. Great content and well executed and straightforward. Well done.

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

    Keep it up. Informative video👍

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

    Great content, very helpful video. Thanks for your efforts.

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

      Your welcome. I am glad you found it helpful.

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

    You saved the day! I had t use oauth 2.0 in postman and not the bearer token dropdown

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

    Top quality stuff!

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

    Thanks a lot! That's exactly what we need. We want to use Amazon S3 with an existing Keycloak instance and use JWT Token authentification

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

    Nice and to the point

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

    Very useful. Thank you.

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

    Thank you so much!!

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

      I am glad you found the vudeo helpful...I plan to make more...just haven't had time lately. Hopefully soon.

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

      I really appreciate it. Yesterday spend whole day and the authorization was not working. So after watching your video, I fixed it 15 minutes!!

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

    Great video! So how does it all work on the front end? using JaveScript how does one use the host UI and retrieve the token and store and use it?

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

      The hosted UI was more for Demo. How I have implemented this in production is to have the server side code of the website call cognito to grab a token and pass this to my front-end UI to use in an AJAX call to the service. Doing this won't expose the username/password. This way the UI has a token ready to call the api as needed. I have used the hosted UI in my projects to offer QA a way to manually grab tokens in case they wanted to test the web service calls directly without any UI.

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

    The AWS Cognito interface has changed, the setup is very different from what's shown in this video.

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

      Agreed, the screens have changed...but the concept is essentially the same. When i have time i will do an updated video.

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

    I'm a little lost... perhaps I've jumped in too deep before reading up more, but in essence how or what would you give a third party that you wanted to allow to access your API?

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

      You would create a user for them within Amazon Cognito. They would then use these credentials to call and authenticate against Amazon Cognito (via various methods - AWS SDK, Postman like in the video) to get back the ID_TOKEN. Then they would call the API using the public API Gateway address passing the token which gets validated with the custom authorizer. Maybe start again at the beginning of the video and take it one step at a time....hope that helps :)

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

      @@letsfindsolutions hello thanks for the quick and detailed reply. That makes sense I think. So to confirm though, all I would provide them is the username/password but they could then get the ID_TOKEN in code rather than manually copy and paste as you showed.

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

      @@AthelstanEngland correct...they can call cognito using aws sdk...provide username and password...and it will return the api tokens.

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

      @@letsfindsolutions super, thanks very much for taking the time to reply.

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

      Glad to help out.

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

    I have implemented Cognito authentication for my .net web api / react app. It's in .net 4.8 framework and hosted in iis localhost. Also using IIS Url rewrite to configure IIS that react router handlea the app navigations after authentication is completed.
    Issue is when we make Cognito logout api endpoint get request, it throws CORs error stating Allow Content Header Origin is not present.
    I have the proper app domain, client id and redirect uri.
    So what needs to be done in this situation for logout to work.
    Cognito login works perfectly

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

      Did you try enabling cors on the api gateway?

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

    why implicit grant rather than Authorization code grant? Aws doesn't recommend using Implicit Grant

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

      We are using jwt tokens. In not sure on the question.

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

    7:53 When you change the password the second time, it says 'localhost has refused to connect'.
    How can I solve this?
    8:44 I tried it on Postman, but I couldn't get the token's value and it came out the same way

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

      Not really sure of the issue...just make sure you are using the id token and not the access token. Postman finally updated the ability to use the id token...so maybe try again.

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

    How can i use this token further in aws lambda to get the email id or username to do some dynamic processing? Are there any cognito sdk or library available to scrap that Information in aws lambda ?

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

      I believe you can get the user id or group id of the user from the token. From their you can have a dynamo db table to do mapping and dynamic logic based on your custom lookup.

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

      Seems like you can get it from event.requestContext.authorizer

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

    AWS UI changed now. Cognito UI looks entirely new and unable to get published the user login page.😥

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

      See if you see the option for classic mode...if so you xan switch back to that view maybe

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

    how can i use access token here instead of ID token to authenticate our API?

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

      I have only ever had this work with the ID Token, but I think if you want to use the Access Token, you may have look into writing your own custom authorizer lambda, and then have it validate the access token.