Anybody can hit that URL & get a response. If you don’t want that, there are several ways to secure an API endpoint such that API Gateway won’t invoke the API unless the caller authenticates itself. One way to secure APIs is by using Amazon Cognito. Let’s see how to set this up for an app that intends to call a secure API.
We’ll begin by creating a Cognito user pool:
We’ll step through settings so we can customize them:
We don’t require any attributes since this pool will only be used by apps programmatically:
No need to allow users to sign themselves up:
No need to verify any attributes. We don’t intend to send any SMSes either:
Add an app client & create the pool:
Provide a domain name so we can fetch the tokens:
Add a resource server:
Enable the Cognito identity provider & the “client credentials” OAuth flow for the app:
Now let’s use this pool to secure the API. Back in the API Gateway console, create a new authorizer of type Cognito:
Now go into the Method Request of the method you wish to secure & change its Authorization from NONE to our authorizer:
Harish KM is a Cloud Evangelist and a Full Stack Engineer at QloudX. Harish is very passionate about cloud native solutions and using the best tools for projects. This means that he is an expert in a multitude of application languages and is up to date with all the new offerings and services from cloud providers, especially AWS.
One Reply to “Securing REST APIs in Amazon API Gateway using Amazon Cognito User Pools and OAuth 2.0”
Qloudx takes your privacy and security seriously.
We use cookies to collect information about you.
We use this information:
1. to give you a better experience (functional)
2. to count the pages you visit (statistics)
3. to serve you relevant promotions (marketing)
Click “ACCEPT” to give us your consent to use cookies for all these purposes.
Read more about how we use cookies to collect personal data: Privacy Policy
This website uses cookies to improve your experience while you navigate through the website. Out of these cookies, the cookies that are categorized as necessary are stored on your browser as they are as essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may have an effect on your browsing experience.
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
[…] This article describes how to secure an API in Amazon API Gateway. Here we’ll see how to invoke a secure API programmatically from Angular. […]