I'm interested in logging information about which Cognito authorized users are making chalice requests. Briefly in late 2016/early 2017, it looks like the Cognito claims were included as a top level item on the Request object: https://github.com/aws/chalice/commit/b5030ca645c95db112f50e4fa9a06a4a5e9aaf32#diff-92c4bff78ea0a0fdf94c7dae50063163
This object was removed here:
https://github.com/aws/chalice/pull/240
with the comment, "Need to figure out claims key. This was originally a top level key,
and I believe this is now moved into the request context. Need to double check."
As far as I can tell, the claims aren't currently being passed along with my request context. I am getting the token in my authorization header, and in the short term I can decode that for the user information, but I'm not thrilled with that as a long term solution.
Is there currently a straightforward way to access Cognito claims that I am missing? Or does that need attention.
Thanks!
Yeah the claims should be available through the request.context property. I have an example of how you can do this in a sample chalice trivia application that I wrote where it uses a CognitoUserPoolAuthorizer for authorization: https://github.com/kyleknap/chalice-trivia/blob/3c23543c511db10e1b2a60e306daec2c1079d998/app.py#L82-L84
Let us know if using the request.context property works for you.
Thank you, that is very helpful-and I'm sure that other parts of this sample app will be a useful reference as well.
Most helpful comment
Yeah the claims should be available through the
request.contextproperty. I have an example of how you can do this in a sample chalice trivia application that I wrote where it uses aCognitoUserPoolAuthorizerfor authorization: https://github.com/kyleknap/chalice-trivia/blob/3c23543c511db10e1b2a60e306daec2c1079d998/app.py#L82-L84Let us know if using the
request.contextproperty works for you.