0
votes

We currently have a .NET Core 3.1 app that uses AWS Cognito to log in - that works all fine.

However, we are struggling to get an access token (JWT) which we can then pass on to a request to a Lambda function. All the guides I find seem are either outdated or missing something crucial.

It would be great if we could get the token automatically but then also retrieve it on demand from user claims or similar. We can then add the Bearer token to the request header calling a Lambda function via the API Gateway.

Below is what I have, but I have two issues:

  1. It doesn't provided an error if I purposely give it false information. Is this correct?
  2. I don't know how to get the token from a PageModel so that I can add the token to a header before making a GET request to a Lambda function.

Updated version

2

2 Answers

0
votes

You can't really supply the key here because AWS will change it frequently. The solution is to have the code look it up dynamically. This answer to a similar question should help you out.

0
votes

In the end it just required on line in the pages controller.

var it = HttpContext.GetTokenAsync(OpenIdConnectParameterNames.IdToken);   

Then the result of that can be put into a request Authorisation header.