3

I am looking to create one API via AWS Amplify that I can query/post to from React and React Native. I set up the API and Lambdas via serverless, and a user pool manually via the Cognito console, with two separate app clients for each platform. The React setup went swimmingly, all gets/posts/puts to the API work as expected.

React-Native has proven to be a little more hairy. I manually configured Amplify with the same values as in the React project, except for APP_CLIENT_ID, to match the app client in the user pool in Cognito.

The Auth calls (SignIn, SignUp) all work fine, so the config is at least partly ok. But the same REST API calls that work perfectly in React respond with 403s in Native, Missing Authentication Token. (Same user). I poked around the documentation and saw that I may need to use a custom_header in my Native config:

Amplify.configure({
  API: {
    endpoints: [
      {
        name: 'testapi',
        endpoint: config.apiGateway.URL,
        region: config.apiGateway.REGION,
        custom_header: async () => {
          return {
            Authorization: (await Auth.currentSession()).idToken.jwtToken
          };
        }
      }
    ]
  }
});

This clears the Missing Authentication Token error, but now I get: Authorization header requires 'Credential' parameter. Authorization header requires 'Signature' parameter. Authorization header requires 'SignedHeaders' parameter. Authorization header requires existence of either a 'X-Amz-Date' or a 'Date' header.

I compared the full requests via the Chrome console, and it looks like the Authorization header in React is correctly generated via Amplify, with Credential, Signature, SignedHeader, etc. It looks vastly different in Native, as the custom_header change above just sets the Authorization header to a jwtToken.

user2755635
  • 137
  • 1
  • 1
  • 4

0 Answers0