in src/main/java/com/aws/sap/sample/lambda/sap/oauth/SAPOAuthHandler.java [157:184]
private String getNameId(JSONObject inJson) {
logger.log("...Try to get name ID from request context");
String returnValue = "";
try {
JSONObject requestContext = (JSONObject) getChildJson(inJson,"requestContext");
logger.log("....received requestContext");
JSONObject authorizer = (JSONObject) getChildJson(requestContext,"authorizer");
logger.log("....received authorizer");
JSONObject claims = (JSONObject) getChildJson(authorizer,"claims");
logger.log("....received claims");
String identitiesAsString = (String) claims.get("identities");
logger.log("....received identities string" + identitiesAsString );
if(identitiesAsString !=null) {
JSONObject identities = (JSONObject)parser.parse(identitiesAsString);
logger.log("....received identities");
returnValue = (String) identities.get("userId");
logger.log("....received userId from identities" + returnValue );
}else {
logger.log("....trying to get cognito username instead");
returnValue = (String) claims.get("cognito:username");
logger.log("....received cognito user name" + returnValue);
}
}catch(Exception e) {
logger.log("error getting nameid " + e.getMessage());
}
return returnValue;
}