Search code examples
node.jsamazon-web-servicesamazon-cognito

Obtain user data from Cognito after successful authentication with AWS load balancer


I've a NodeJS app that serves ReactJS frontend.
I'm using AWS Application Load Balancer authentication with a Cognito user pool. I've set up a role in my load balancer and as soon as the user enters the url of my app, the authentication is being performed and two AWSELBAuthSessionCookie cookies are set.

This flow works perfectly, but the thing is that I would like to obtain also the current user info from Cognito (name, email, etc..).

As i understood the other parameters like X-amzn-oidc-data are not available in the frontend and only available to the backend.

My questions is, how can i obtain this information assuming that i have only the AWSELBAuthSessionCookie available in my NodeJS backend?

Any help would be appreciated.


Solution

  • You would have to build a back-end API endpoint that exposes that user information. Something like yourdomain.com/api/get_user_info. Then have your front-end ReactJS application call that API endpoint to retrieve it from the back-end.