API Gateway HTTP API > JWT authorizer > VPC Link > ECS instance - How to access JWT claims?

1

I know if you use a Lambda integration with a JWT authorizer, the claims are added to event.requestContext. But when the request is sent to a server (in my case Node.js) running on an ECS instance, is there a way to access those claims? Or do I need to decode the token again? Many thanks.

1개 답변
1
수락된 답변

Hi James, thanks for asking this question on re:Post!

You can use Parameter mapping feature of the HTTP API integration to add claims from the context of your JWT authorizer as custom headers of the request forwarded to the server. Please see the screenshot below.

Appending a custom header to the request

The claim path example $context.authorizer.jwt.claims.emailID can be found in our documentation. Please let us know if this solution worked for you!

AWS
Piotrek
답변함 9달 전
profile pictureAWS
전문가
검토됨 9달 전
  • Thanks Piotrek, that's great! Just one issue I've found one of the claims I want to forward is cognito:username. The colon seems to be causing problems in the parameter mapping, with an error

    Invalid mapping expression specified: Validation Result: warnings : [], errors : [Invalid mapping expression specified: $context.authorizer.claims.cognito:username]

    I've tried various ways around it but nothing is working, any suggestions?

    Many thanks

  • Unfortunately cognito:username and cognito:groups are the two claims I'm most interested in. I'll have to stick to decoding the token on the server for now. Thanks for your help!

  • Sure! For the additional issue you mentioned, it seems that the properties/paths containing a colon are not supported the moment. I was able to find a similar known issue for ALB integration deployed with CDK, and made sure to provide more context that will help us to prioritise this issue. Are you able to use any other claims (without colons) to satisfy your use case? Alternatively, like you noted, it should be possible to decode the token again on the server side.

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠