【问题标题】:AWS Appsync 401 and 403 errors in React NativeReact Native 中的 AWS Appsync 401 和 403 错误
【发布时间】:2018-12-09 15:30:16
【问题描述】:

我一直在努力在我的 React Native 应用程序中设置 Appsync 和 Cognito。

我尝试了以下两种方法:

Amplify.configure(config);

OR

Amplify.configure({
  Auth: {
    region: config.aws_cognito_region, // REQUIRED - Amazon Cognito Region
    userPoolId: config.aws_user_pools_id, // OPTIONAL - Amazon Cognito User Pool ID
    userPoolWebClientId: config.aws_user_pools_web_client_id, // User Pool App Client ID
  },
});

const client = new AWSAppSyncClient({
  url: appSyncConfig.graphqlEndpoint,
  region: appSyncConfig.region,
  auth: {
    type: appSyncConfig.authType,
    jwtToken: async () => (await Auth.currentSession()).getIdToken().getJwtToken(),
  },
});

OR

const client = new AWSAppSyncClient({
  url: appSyncConfig.graphqlEndpoint,
  region: appSyncConfig.region,
  auth: {
    type: appSyncConfig.authType,
    apiKey: appSyncConfig.apiKey,
  },
});

我也跟着这两个教程Tackling user authBuilding a notes app

在这两种情况下,我都在 GraphQL 中收到以下错误,没有描述:

Error: Network error: Response not successful: Received status code

这是在授权类型为Amazon Cognito User Pool 时。我也试过AWS Identity and Access Management (IAM),但这给了我一个403错误。有人可以指出我可以进一步调试的方向吗?

【问题讨论】:

    标签: amazon-web-services react-native amazon-cognito amazon-iam aws-appsync


    【解决方案1】:

    这可能是您阅读的文档/文章中的拼写错误造成的。尝试替换:

    auth: {
    type: appSyncConfig.authType,
    apiKey: appSyncConfig.apiKey
    }
    

    与:

    auth: {
    type: appSyncConfig.authenticationType,
    apiKey: appSyncConfig.apiKey
    }
    

    【讨论】:

      【解决方案2】:

      我有以下代码及其为我工作:

      import Amplify, { Auth } from 'aws-amplify';
      import API, { graphqlOperation } from '@aws-amplify/api'
      
      window.LOG_LEVEL = 'DEBUG';
      Amplify.configure({
        Auth: {
          "identityPoolId":'ap-southeast-1:xxxxxx',
          "mandatorySignIn": false,
          "region": "ap-southeast-1",
          "userPoolId": "ap-southeast-1_xxxx",
          "userPoolWebClientId": "xxxxxxx"
        },
        API:{
          "aws_appsync_graphqlEndpoint": 'https://xxxx.ap-southeast-1.amazonaws.com/graphql',
          "aws_appsync_region": 'ap-southwest-1',
          "aws_appsync_authenticationType": 'AMAZON_COGNITO_USER_POOLS',
          "aws_appsync_apiKey": 'null',
        }
      
      });
      

      【讨论】:

        猜你喜欢
        • 2021-07-03
        • 2017-04-26
        • 2019-08-08
        • 2018-10-27
        • 1970-01-01
        • 2020-03-20
        • 2019-03-22
        • 1970-01-01
        • 2019-06-25
        相关资源
        最近更新 更多