Skip to content

Commit 237a7c7

Browse files
committed
Added code to handle Cognito Credentials and return the identity id instead of the user ARN. This fixes issue #43
1 parent 0e762c6 commit 237a7c7

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

aws-serverless-java-container-core/src/main/java/com/amazonaws/serverless/proxy/internal/jaxrs/AwsProxySecurityContext.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,12 @@ public Principal getUserPrincipal() {
6969
if (getAuthenticationScheme().equals(AUTH_SCHEME_CUSTOM)) {
7070
return event.getRequestContext().getAuthorizer().getPrincipalId();
7171
} else if (getAuthenticationScheme().equals(AUTH_SCHEME_AWS_IAM)) {
72-
return event.getRequestContext().getIdentity().getUserArn();
72+
// if we received credentials from Cognito Federated Identities then we return the identity id
73+
if (event.getRequestContext().getIdentity().getCognitoIdentityId() != null) {
74+
return event.getRequestContext().getIdentity().getCognitoIdentityId();
75+
} else { // otherwise the user arn from the credentials
76+
return event.getRequestContext().getIdentity().getUserArn();
77+
}
7378
} else if (getAuthenticationScheme().equals(AUTH_SCHEME_COGNITO_POOL)) {
7479
return event.getRequestContext().getAuthorizer().getClaims().getSubject();
7580
}

0 commit comments

Comments
 (0)