2017-01-03 74 views
4

使用V1.10 Cognito用户群。如何验证在亚马逊cognito身份-JS在以下nodeapp的节点JS

我写了下面的: 用户注册已被证实后,将调用该函数和电子邮件已经过验证。

var AWS = require('aws-sdk'); 
var AWSCognito = require('amazon-cognito-identity-js'); 

router.post('/emailsignin', function(req, res, next) { 
var email = req.body.email; 
var pwd = req.body.password; 

AWS.config.region = 'eu-west-1'; 
var poolData = { 
    UserPoolId : AWS_USERPOOLID, 
    ClientId : AWS_APPCLIENTID 
}; 
var userPool = new AWS.CognitoIdentityServiceProvider.CognitoUserPool(poolData); 
var authenticationData = { 
    Username : email, 
    Password : pwd, 
}; 
var authenticationDetails = new AWS.CognitoIdentityServiceProvider.AuthenticationDetails(authenticationData); 
var userData = { 
    Username : email, 
    Pool : userPool 
}; 
var cognitoUser = new AWS.CognitoIdentityServiceProvider.CognitoUser(userData); 

cognitoUser.authenticateUser(authenticationDetails, { 
    onSuccess: function (result) { 
    }, 
    onFailure: function(err) { 
} 
}); 

当的authenticateUser被调用时,我得到“的ReferenceError:导航仪没有定义”

它看起来像一个浏览器呼叫正在尝试的节点服务器内部。

我创造了这个一个github上的问题和建议是指 “jsbn”: “^ 0.1.0”, “sjcl”: “^ 1.0.3”, “亚马逊cognito身份-js“:”^ 1.10.0“, ”aws-sdk“:”^ 2.5.3“

我对软件包版本进行了更改。不幸的是,它也不适用于此。 我已经创建了一个示例nodejs应用程序,它尝试使用电子邮件ID和密码进行身份验证。

注:该Cognito池设置与电子邮件别名。用户已创建,确认并通过电子邮件验证。

来源回购:https://github.com/prem911/cognito-nodejs

就如何解决“找不到导航”任何指针?

+0

Cognito是_users_服务来验证AWS,不_servers_ 。这段代码应该放在客户端。 –

+0

如果是这种情况,那么暴露客户端js文件中的aws用户池ID和aws应用程序客户端ID是不好的。我能够从服务器执行联合身份验证。这是否也应该从客户端完成? – prem911

+0

我想你应该回顾一下认知如何工作,如果你认为揭露这些信息是不好的。我不认为你明白这是主要的价值主张。 –

回答