所以我用這個塊的代碼在AWS上JS SDK的官方回購找到。 它用於驗證用戶。AWS Cognito無法驗證:空白答案 - JS SDK
它返回一個空應答。
AWSCognito.config.region = 'us-east-1';
var authenticationData = {
Username : '+1112223333', //some phone number used as an Alias
Password : 'password123456',
};
var authenticationDetails = new AWSCognito.CognitoIdentityServiceProvider.AuthenticationDetails(authenticationData);
var poolData = {
UserPoolId : 'us-east-1_P00l1d', // Your user pool id here
ClientId : 'xxx' // Your client id here
};
var userPool = new AWSCognito.CognitoIdentityServiceProvider.CognitoUserPool(poolData);
var userData = {
Username : 'myusername',
Pool : userPool
};
var cognitoUser = new AWSCognito.CognitoIdentityServiceProvider.CognitoUser(userData);
cognitoUser.authenticateUser(authenticationDetails, {
onSuccess: function (result) {
console.log('access token + ' + result.getAccessToken().getJwtToken());
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
IdentityPoolId : 'xxx', // your identity pool id here
Logins : {
// Change the key below according to the specific region your user pool is in.
'cognito-idp.pool_id_number_here_xxx' : result.getIdToken().getJwtToken()
}
});
},
onFailure: function(err) {
alert(err)
console.log("Error " + err);
},
});
因此,對於authenticationData,我使用電話號碼作爲用戶名(電話號碼設置爲別名)和密碼。我也直接用用戶名嘗試。 UserPoolId和ClientId是正確的,因爲我使用了相同的值來註冊和確認電話號碼。 在userData中,我使用正確的myusername設置了用戶名。
關於身份游泳池,我創建了一個身份池上鍊接到我的App和我的了userpool AWS Console和我更換了價值IdentityPoolId和登錄中的authenticateUser。 雖然我不完全確定登錄中的值。我使用了cognito-idp.POOLIDNUMBER。
AWS的輸出爲空白。 我想我甚至無法訪問服務器,我懷疑角色或身份池的問題(userPool很好,我想)。
我的身份池僅使用AWS Cognito用戶,而不是Facebook或其他身份提供者。
它應該是編輯或評論但不是一個答案 – Deep