frank
frank

Reputation: 1342

Using AWS Amplify authenticated user to communicate with an ALB or API Gateway?

I set up my AWS Cognito integration into my React Native app using amplify add auth according to the guide, all is well and good, I'm able to register and login in the app. The cli wizard associates two app clients with the User Pool it creates: [poolid]_app_client and [poolid]_app_clientWeb.

I would like to have authenticated users be able to communicate with a web app hosted on an EC2 instance. I thought I could use an Application Load Balancer to do this by setting it up to forward authenticated requests to the EC2 instance. Problem is, I'm unable to create an Application Load Balancer default action that authenticates with the Cognito User Pool.

If I choose the App Client associated with the [poolid]_app_clientWeb, I get an error on save: Error creating listener The user pool client must have a client secret. This is the client ID exported by the amplify tools to my React Native app in aws-exports.js.

If I choose the App Client associated with the [poolid]_app_client I get Error creating listener OAuth flows must be enabled in the user pool client.

Not sure how to proceed. Is ALB the way to go or API Gateway?

enter image description here

Upvotes: 4

Views: 2372

Answers (2)

Yeldos Balgabekov
Yeldos Balgabekov

Reputation: 49

You should have made appropriate changes in "User Pools -> App Integration -> App client" settings for your client

Upvotes: 2

frank
frank

Reputation: 1342

API Gateway makes this much more straightforward. After I went through Create API, I was able to create an Authorizer that connected with my Cognito User Pool (the clientWeb one). Then, after creating endpoint Resources, I associated them with the authorizer in the Method Request section of their configuration.

I could then send the identity token I get from Amplify:

(await Auth.currentSession()).idToken.jwtToken

as an HTTP header value to the endpoints I configured.

Upvotes: -1

Related Questions