小编nic*_*ick的帖子

使用Cognito联合身份进行AWS AppSync IAM授权

我正在使用AWS AppSync,并使用Cognito Federated Identities登录用户.

我希望未经身份验证的用户可以访问某些端点,而经过身份验证的用户可以访问其他端点.

我已经使用例如为上述每个配置了IAM角色 "Resource": [ "Region:Account:apis/AppSyncName/types/Mutation/fields/XXX”]

我的问题是 - 我如何使用Cognito Federated Identities获取通过AppSync客户端发送的凭据.

我对AppSync的配置:

const client = new AWSAppSyncClient({
  url: config.AppSync.ENDPOINT,
  region: config.AppSync.REGION,
  auth: {
    type: AUTH_TYPE.AWS_IAM,
    credentials: () => ReturnCredentials()
  }
});
Run Code Online (Sandbox Code Playgroud)

我的登录功能

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); …
Run Code Online (Sandbox Code Playgroud)

amazon-web-services amazon-cognito aws-appsync

5
推荐指数
1
解决办法
1156
查看次数