[英]AWS Cognito login error on AngularJS
我正在使用cognito Amazon Webservice進行用戶管理。
我已經管理了對userPool的簽名,但是每次嘗試登錄到用戶池時,都會出現此控制台錯誤:
Error: this.pool.getUserPoolId is not a function
我不知道getUserPoolId在哪里...
編輯:我在我的代碼的工廠中的登錄功能:
login: function(username, password) {
var authenticationData = {
Username : username,
Password : password
};
var userData = {
Username :username,
Pool : poolData
};
var authenticationDetails = new AWSCognito.CognitoIdentityServiceProvider.AuthenticationDetails(authenticationData);
var cognitoUser = new AWSCognito.CognitoIdentityServiceProvider.CognitoUser(userData);
cognitoUser.authenticateUser(authenticationDetails, {
onSuccess: function (result) {
console.log('access token + ' + result.getAccessToken().getJwtToken());
/*Use the idToken for Logins Map when Federating User Pools with Cognito Identity or when passing through an Authorization Header to an API Gateway Authorizer*/
console.log('idToken + ' + result.idToken.jwtToken);
},
onFailure: function(err) {
alert(err);
},
});
}
有誰知道該怎么辦?
AWS Cognito JavaScript SDK初始化模式要求您將“數據對象”傳遞給AWS開發工具包構造函數。 作為回報,SDK為您提供了具有各種連接方法的AWS“接口”。
我認為從您的代碼中,您使用了data object
而不是隨后的interface
。
例:
// Data Object used for initialization of the interface
const userPoolData = {
UserPoolId: identityPoolId,
ClientId: clientId
}
// The `userPoolInterface`, constructed from your `poolData` object
const userPoolInterface = new AWSCognito
.CognitoIdentityServiceProvider
.CognitoUserPool(userPoolData)
在您提供的代碼中,似乎您正在傳遞userData
對象(用於初始化),在該對象中應該傳遞先前應該已初始化的userPool
接口。
嘗試以下方法:
login: function(username, password) {
// 1) Create the poolData object
var poolData = {
UserPoolId: identityPoolId,
ClientId: clientId
};
// 2) Initialize the userPool interface
var userPool = new AWSCognito
.CognitoIdentityServiceProvider
.CognitoUserPool(poolData)
// 3) Be sure to use `userPool`, not `poolData`
var userData = {
Username : username,
Pool : poolData, // <-- Data?! Oops..
Pool : userPool // "interface", that's better :)
};
var authenticationData = {
Username : username,
Password : password
};
var cognitoUser = new AWSCognito
.CognitoIdentityServiceProvider
.CognitoUser(userData)
var authenticationDetails = new AWSCognito
.CognitoIdentityServiceProvider
.AuthenticationDetails(authenticationData);
cognitoUser.authenticateUser( ...etc... );
}
在線嘗試:
如果有幫助,我將在做筆記的同時做一些例子,同時我將逐步介紹AWS Cognito SDK的例子。 歡迎您查看我正在使用的Github存儲庫。 如果您可以測試一個有效的示例,則可能會有所幫助。
我假設您正在初始化poolData對象:
var poolData = {
UserPoolId : '...', // Your user pool id here
ClientId : '...' // Your client id here
};
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.