I have created an API in AWS API Gateway with 1 REST endpoint. The REST endpoint invokes a Lambda function written in C#. I have also created a AWS Cognito user pool. What I am trying to do is integrate AWS Cognito with AWS Gateway API so that when an unauthenticated user attempts to invoke the REST API, the API will redirect them to the built-in sign-in page for AWS Cognito. Currently, I got as far as integrating the 2 together but when I attempt to invoke the REST API, it simply displays an unauthorized message. Instead of displaying that message, I want it to redirect to the sign-in page at that point. I have read through lots of AWS docs and don't know what I am missing. How would I go about doing this?
To specify app UI customization settingsSign in to the Amazon Cognito console . In the navigation pane, choose User Pools, and choose the user pool you want to edit. Choose the App integration tab. To customize UI settings for all app clients, locate Hosted UI customization and select Edit.
Single Sign-On (SSO) solutions allow users to enter credentials once and access many systems simultaneously. IT administrators can use a local SSO server or a third-party service to manage authentication, allowing for centralized access management.
Yes, you can easily and securely add sign-up and sign-in functionality to your apps with Cognito Identity. Your users can sign-up and sign-in using email, phone number, or user name.
User pools are for authentication (identity verification). With a user pool, your app users can sign in through the user pool or federate through a third-party identity provider (IdP). Identity pools are for authorization (access control).
I was able to solve it by specifying a custom Gateway Response that sends a 302 redirect to the login page in the case of an UNAUTHORIZED response from Cognito. In Terraform, it looks like this:
resource "aws_api_gateway_gateway_response" "unauthorized" {
rest_api_id = "${aws_api_gateway_rest_api.apiGateway.id}"
status_code = "302"
response_type = "UNAUTHORIZED"
response_templates = {
"application/json" = "{'message':$context.error.messageString}"
}
response_parameters = {
"gatewayresponse.header.Location" = "'https://example.com/login'"
}
}
I figured out a solution to this. I gave up on my original approach and ended up doing this:
This accomplishes what I was looking for.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With