Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AWS Amplify Gateway REST - React & React Native (403) #2794

Closed
jeff-rogers opened this issue Mar 3, 2019 · 3 comments
Closed

AWS Amplify Gateway REST - React & React Native (403) #2794

jeff-rogers opened this issue Mar 3, 2019 · 3 comments
Labels
API Related to REST API issues investigating This issue is being investigated React Native React Native related issue

Comments

@jeff-rogers
Copy link

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 separate app clients for each platform.

  • The React setup went swimmingly, all gets/posts/puts to the API work as expected.
  • The React-Native REST API calls return 403s.

I manually configured Amplify in the RN repo 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 Amplify Auth calls (SignIn, SignUp) all work fine, so the config is at least semi-ok. It's just the REST API calls that do not. 403s, 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
          };
        }
      }
    ]
  }
});

Setting this custom_header 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.

Thoughts here? Is something like this even supported?

Thanks.

@elorzafe elorzafe added help wanted API Related to REST API issues React Native React Native related issue investigating This issue is being investigated labels Mar 4, 2019
@powerful23
Copy link
Contributor

@jeff-rogers I don't think you need to configure the custom_header because Amplify will do that for you. Can you check the following items:

  1. Did you correctly configure the app client id for your RN app?
  2. What's your app client settings?
  3. Did you use Cognito Federated Identity Pool to retrieve the AWS Credentials?
  4. Which authorization type are you using? https://aws-amplify.github.io/docs/js/api#manual-configuration

@jeff-rogers
Copy link
Author

Thanks for this... closing the issue as I figured it out while looking into #1 and #2 above. I didn't correctly configure the 2nd app client ID (for the RN app) in the identity pool. Once I did that, all was good.

I'm a little confused as to why my calls to Auth via Amplify (non-REST) worked fine before fixing the above. But I'm clear of the issue now. Thanks again.

@github-actions
Copy link

This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels or Discussions for those types of questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
API Related to REST API issues investigating This issue is being investigated React Native React Native related issue
Projects
None yet
Development

No branches or pull requests

3 participants