0

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으로 설정합니다.

ID 풀에 관해서, 필자는 내 App과 내 UserPool에 연결된 AWS Console에 Identity 풀을 만들고 identityPoolId 및 LogininsecurityUser 값을 대체했습니다. 로그인의 가치에 대해서는 완전히 확신 할 수 없습니다. 나는 cognito-idp.POOLIDNUMBER를 사용했습니다.

AWS의 출력이 비어 있습니다. 나는 심지어 서버에 연결할 수 없다고 생각하고 있으며 역할이나 Identity Pool (userPool은 괜찮습니다) 문제를 의심합니다.

내 ID 풀은 Facebook 또는 다른 ID 공급자가 아닌 AWS Cognito 사용자 만 사용합니다.

답변

0

--with-all을 사용하여 SJCL을 다시 컴파일하면 문제가 해결됩니다.

+0

편집 또는 댓글이어야합니다. 대답이 없습니다. – Deep

0

'자바 스크립트 용 Amazon Cognito Identity SDK'에 필요한 모든 라이브러리가 있는지 확인하십시오. 다음은이 라이브러리에 대한 목록과 링크입니다. 자바 스크립트

1. 아마존 Cognito AWS SDK - 자바 스크립트에 대한 https://raw.githubusercontent.com/aws/amazon-cognito-identity-js/master/dist/aws-cognito-sdk.min.js

2. 아마존 Cognito 신원 SDK - https://raw.githubusercontent.com/aws/amazon-cognito-identity-js/master/dist/amazon-cognito-identity.min.js

3.JavaScript BN 라이브러리 (jsbn.js, jsbn2.js) - http://www-cs-students.stanford.edu/~tjw/jsbn/

4.Stanford 자바 스크립트 암호화 라이브러리 - https://github.com/bitwiseshiftleft/sjcl

자바 스크립트 용 5.AWS SDK (선택 사항, 다른 aws 서비스 사용) - http://aws.amazon.com/sdk-for-browser/

아래의 코드 스 니펫을 모두 포함하십시오.

AWSCognito.config.region = 'YOUR_REGION'; 
var poolData = { 
    UserPoolId : 'YOUR_USER_POOL_ID', // Your user pool id here 
    ClientId : 'YOUR_CLIENT_ID' // Your client id here 
}; 
var userPool = new AWSCognito.CognitoIdentityServiceProvider.CognitoUserPool(poolData); 
var userData = { 
    Username : "userName", // your username here 
    Pool : userPool 
}; 
//Signing Users in the App 
var authenticationData = { 
    Username : "userName", // your username here 
    Password : "password" // your password here 
}; 

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()); 
    }, 
    onFailure: function(err) { 
     console.log(err); 
    } 
}); 
+0

도움이 되었습니까? –