2017-09-08 72 views

回答

1

如果您已经检查了AWS_IAM API网关,最终用户的身份可用于您的功能。您可以按如下方式访问身份证件。

exports.handler = function(event, context) { 
    var identity = event.requestContext.identity.cognitoIdentityId; 
    console.log("clientID = " + identity); 

    context.succeed("Your client ID is " + identity); 
} 

然后使用AWS SDK for Cognito调用describeIdentity-property方法,你应该能够检索可用于识别的附加信息。

var params = { 
    IdentityId: 'STRING_VALUE' /* required */ 
}; 
cognitoidentity.describeIdentity(params, function(err, data) { 
    if (err) console.log(err, err.stack); // an error occurred 
    else  console.log(data);   // successful response 
}); 
+0

没有context.identity属性。我使用https调用API https://www.npmjs.com/package/aws-api-gateway-client 上下文对象具有以下属性:callbackWaitsForEmptyEventLoop,logGroupName,logStreamName,functionName,memoryLimitInMB,functionVersion,invokeid,awsRequestId,invokedFunctionArn – Ildar

+0

但是,事件对象中是event.requestContext.identity.cognitoIdentityId。谢谢 – Ildar

+0

我检查了移动SDK的调用。但是,谢谢你会相应地更新答案。 – Ashan

相关问题