-
Notifications
You must be signed in to change notification settings - Fork 559
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for Cognito User Pool authorizer #24
Comments
This is currently my most-wanted :) |
Thanks. Working on this now. It may result in an API change. I will probably have to change the shape of the |
Just committed a first implementation of this. You can try it by cloning this branch and running The branch is for version request.getRequestContext().getAuthorizer().getClaims(); |
Excited :) Checking out and using that branch, I'm now able to authenticate via cognito-user-pools (like before) but now my Lambda isn't throwing back I am getting this following error when trying to do
|
Could you share the code at (and around) LambdaHandler.java:36? |
Here's the full class, without imports that was built off of the samples. Our container is based off of the Spring Container, but we're not currently //line 13
public class LambdaHandler implements RequestHandler<AwsProxyRequest, AwsProxyResponse> {
private PangeaLambdaContainerHandler<AwsProxyRequest, AwsProxyResponse> handler;
public AwsProxyResponse handleRequest(AwsProxyRequest awsProxyRequest, Context context) {
if (handler == null) {
try {
handler = PangeaLambdaContainerHandler.getAwsProxyHandler();
} catch (ContainerInitializationException e) {
e.printStackTrace();
return null;
}
}
try {
//line36
System.out.println("identity?: " + awsProxyRequest.getRequestContext().getAuthorizer().getClaims());
} catch (Exception e) {
e.printStackTrace();
}
return handler.proxy(awsProxyRequest, context);
}
} |
What's the exception? Was that a NullPointer? |
Yes it was However, on further investigation (I was looking at old logs)... I get this only if I invoke from the lambda console, I get what I assume is expected if I route through API gateway endpoint with When invoking through API-gateway I get this from line 36:
|
That's the expected behavior. When testing from the Lambda console, make sure that your test event contains the user pools context. Take a look at the sample event in the tests When invoking from API Gateway, you are getting the expected behavior. The Claims object contains all the info from the user pools (getSubject, getIssuer, etc). I've made a small fix that I'm about to push, please pull again in a minute. |
Fixed the principal id in the JaxRs security context to read the subject property from the user pools authorizer claims. Fixed a bug in the Claims object (private getSubject method). Added some comments to the `ZonedDateTime` methods in the claims object. This should completely address #24.
Thank you for the link to the sample event. I'm currently trying to grab a cognitoIdentityId from an authorized request with I used this as a reference. System.out.println("auth scheme?: " + awsProxyRequest.getRequestContext().getIdentity().getCognitoAuthenticationType());
System.out.println("identity?: " + awsProxyRequest.getRequestContext().getIdentity().getCognitoIdentityId()); Perhaps I'm missing permissions somewhere? |
The Cognito identity is populated only if you are using AWS_IAM as the authorization strategy and the temporary credentials you use to make the call were generated by the Cognito Identity service. If you are looking for the User Pool identity id then you need to you the
|
By the way, are you building support for a new container? What is |
Thank you for the insight. That makes much more sense now x-ref'ing the https://github.com/awslabs/aws-serverless-auth-reference-app Pangea is whom I work for, our container is a WIP and may be dropped ultimately but it's useful for me right now to understand the library. I also started the container because I wasn't sure why I was getting public class Task implements RequestHandler<AwsProxyRequest, AwsProxyResponse> {
public handler(AwsProxyRequest event, Context context) {
//do stuff
return new AwsProxyResponse(200, null, "{\"message\": \"Hello, from Lambda!\"}");
}
} |
Great. I'll merge this into master soon. By the way, I've just created a gitter room for this repo: https://gitter.im/awslabs/aws-serverless-java-container |
This is merged into master. Closing issue. |
Update internal methods to support the
claims
object in the request authorization context. This is relevant when an API is configured with a User Pool authorizer from Amazon Cognito.The text was updated successfully, but these errors were encountered: