我正在使用 AWS AppSync,并使用 Cognito 联合身份登录用户。
我希望未经身份验证的用户可以访问某些端点,而经过身份验证的用户将可以访问其他端点。
我已经为上述每个配置了 IAM 角色,例如 "Resource": [ "Region:Account:apis/AppSyncName/types/Mutation/fields/XXX”]
我的问题是 — 我如何使用 Cognito 联合身份获取凭据以通过 AppSync 客户端发送。
我对 AppSync 的配置:
const client = new AWSAppSyncClient({
url: config.AppSync.ENDPOINT,
region: config.AppSync.REGION,
auth: {
type: AUTH_TYPE.AWS_IAM,
credentials: () => ReturnCredentials()
}
});
我的登录功能
login(username, password) {
const user = new CognitoUser({ Username: username, Pool: userPool });
const authenticationData = { Username: username, Password: password };
const authenticationDetails = new AuthenticationDetails(authenticationData);
var responseFunctions = {
onSuccess: result => {
},
onFailure: err => {
console.log(err);
}
};
user.authenticateUser(authenticationDetails, responseFunctions);
}
我想我需要在登录后使用GetCredentialsForIdentity,但不确定如何将这些传递到 AppSync 配置中。此外,如何获取未经身份验证的用户的凭据?