question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

API access unauthenticated error using IAM as an additional auth mode on client

See original GitHub issue

Which Category is your question related to? Multiple auth modes on API

Amplify CLI Version 4.4.0

What AWS Services are you utilizing? Amplify Auth, Amplify API, Lambda resolver

Provide additional details e.g. code snippets My API has the default auth mode set as cognito user pool and one additional auth mode as IAM. However when I access the API with the following code with amplify generated aws-exports.js config:

    const res = await API.graphql({
      query: queries.getHanShanRate,
      variables: {input: {currency: 'CNY'}},
      authMode: 'AWS_IAM'
    });
    console.log(res);

I get the following error with code 401:

{
  "errors" : [ {
    "errorType" : "UnauthorizedException",
    "message" : "Permission denied"
  } ]
}

However in the Appsync web console, using the IAM auth mode do the same query returns the expected result shown in the screen shot below:

Screenshot 2020-05-04 at 4 17 18 PM

Do I need additional IAM configurations on the client side? The documentation is lacking in this regard and there isn’t much examples that I can follow. My graphql schema as shown in AppSync web console (as current graphql transform library does not yet support multiple auth modes):

# this query invokes a lambda resolver to get data from an external source
type Query {
	getHanShanRate(input: getReferenceRateInput): ReferenceRateResult
		@aws_iam
}

type ReferenceRateResult @aws_iam {
	currency: Currency
	rate: Float
	fee: Float
	feeCurrency: Currency
	updatedAt: AWSDateTime
}

My intention for this setup is straight forward: I need to open some APIs to unauthenticated users while other APIs are protected by cognito user pool by default. Is there a better way of achieving the same goal?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
kaustavghosh06commented, Oct 22, 2020

@hello2all Are you still stuck on this issue? For non-model types you can use @aws_iam decorator and the transformer will passthrough this directive. cc @attilah

0reactions
github-actions[bot]commented, May 25, 2021

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 for those types of questions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Enabling unauthenticated access with AWS Amplify
The preferred method of authorization relies on IAM with tokens provided by Cognito User Pools or other OpenID Connect providers.
Read more >
Resolve unauth errors for GraphQL requests in AWS AppSync
401 Unauthorized: The request is denied by either AWS AppSync or the authorization mode because the credentials are missing or invalid.
Read more >
How to properly handle unauthenticated users and requests in ...
Using the following steps, you can allow both Authenticated & Unauthenticated access to your AWS AppSync API: Create an Amplify project.
Read more >
API (REST) - Define authorization rules - Android - Amplify Docs
IAM authorization has two modes: one using an unauthenticated role, and one using an authenticated role. When the user has not signed in...
Read more >
Part 05: AWS AppSync: Guest/Unauthenticated User Access ...
Learn how to provide Guest/ Unauthenticated User Access to your backend AppSync API with Cognito Identity Pool Join "The Complete Guide...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found