사용자 풀과 함께 AWS Cognito를 사용하여 API를 통해 인증을 받으려고합니다. AWS Cognito User Pool을 통해 생성 된 사용자가 있는데 사용자와 로그인하려고합니다.AWS - nodejs SDK - CognitoIdentityServiceProvider.initiateAuth - CredentialsError : 설정에 자격 증명이 누락되었습니다.
내가받는 오류는 CredentialsError: Missing credentials in config
입니다. 특히 그것은 IdentityPoolId
이 필요하다는 것을 나에게 말하고 있었다. 하지만 내 AWS 콘솔에서이 IdentityPoolId
을 찾지 못했습니다. 도데체 어디에서 내 사용자 풀을 얻을 수 있습니까? 내가보기에는 풀 ID와 풀 ARN 만 있습니다.
관련 소스 코드 : authParams
객체의 경우
var aws = require('aws-sdk');
aws.config.update({
region: 'us-east-1',
credentials: new aws.CognitoIdentityCredentials({
IdentityPoolId: '???'
})
});
var authUser = function(params, callback)
{
if (!params || !params.Email || !params._password)
{
callback(new Error('Invalid parameters.'));
return false;
}
var cognito = new aws.CognitoIdentityServiceProvider();
var authParams = {
AuthFlow: 'USER_SRP_AUTH', // not sure what this means...
ClientId: conf.AWSConfig.ClientId,
AuthParameters: {
Username: params.Email,
Password: params._password
}
};
cognito.initiateAuth(authParams, function(err, data)
{
if (err)
{
console.log('Error details: ' + util.inspect(err));
callback(err);
return false;
}
callback(null, {success: true, data: data});
});
}
, 나는 AuthFlow
될해야하는지 모르겠어요. http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/CognitoIdentityServiceProvider.html#initiateAuth-property을 보면 USER_SRP_AUTH
과 같은 것 같습니다.
편집 :
나는 나의 IdentityPoolId
을 얻기 위해 어디 발견 할 수 있습니다 생각합니다. 내 Federated Identities
섹션을보고 ID 풀을 편집하는 동안 Authentication Providers
섹션 아래에 적절한 User Pool
을 추가했습니다.
나는 그 사용자 풀의 User Pool ID
및 App Client ID
를 입력하여 만들어 내 사용자 풀에 Cognito
에 대한 Authentication Provider
을 관련. 이제 같은 코드를 사용하여 Identity pool ID
나는 CredentialsError: Missing credentials in config
오류가 나타납니다. 그것은 Unauthorized access is not supported for this identity pool
라고합니다. 확인 ... 사용자를 인증하려고합니다 ... 인증되지 않은 사용자가 인증 할 수 있도록 인증되지 않은 역할을 만들어야합니까? 그게 내가해야 할 일이라면 어리석은 것처럼 보입니다.
편집 2 :
은 내가 로그인 자바 스크립트 SDK를 (하지 nodejs)를 사용하여뿐만 아니라 IdToken
및 RefreshToken
로 AccessToken
를 얻을 수 있었던 것 또한주의해야한다. 나는 IdentityPoolId
의 필요없이 이것을했다. 내가 필요한 유일한 것들은 UserPoolId
과 ClientId
입니다.
var authenticateUser = function(onSuccessCallback)
{
var authData = {
Username: getUserName(), // gets username from an html text field
Password: getPassword() // gets password from an html password field
};
var authDetails = new AWSCognito.CognitoIdentityServiceProvider.AuthenticationDetails(authData);
var cognitoUser = getCognitoUser();
cognitoUser.authenticateUser(authDetails,
{
onSuccess: function(result)
{
console.log('access token: ' + result.getAccessToken().getJwtToken());
console.log('idToken: ' + result.idToken.jwtToken);
console.log(result);
if (onSuccessCallback && typeof(onSuccessCallback) == 'function')
{
onSuccessCallback(cognitoUser);
}
},
onFailure: function(err)
{
// UserNotConfirmedException: User is not confirmed.
console.log('authError');
alert(err);
}
});
}