-
Notifications
You must be signed in to change notification settings - Fork 824
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
Unexpected "Not Authorized" with Lambda Authorizer and Transformer v2 #10047
Comments
What is the authorization token (authorizationToken) received by your Lambda authorizer function ? I had an almost similar issue whereby using the cognito JWT token as authorizationToken for the Lambda authorizer would cause |
@rezab777 the token is already a custom string. It's either a string in the format Edit: Wow, you were onto something! I took another look, and ended up stumbling on this issue: aws-amplify/amplify-js#9513
Edit #2: Ah, I spoke too soon. I tried prefixing the token with However, I updated the lambda to accept a
|
@jevakallio - Could you check the value of key Also, you can explicitly specify the authMode as shown below. Let me know if this helps. const createdTodo = await API.graphql({
query: queries.createTodo,
variables: {input: todoDetails},
authMode: 'AWS_LAMBDA'
}); I just tested the Thanks for mentioning about the docs, it definitely needs an update. |
@sundersc thanks for a quick reply! What are the headers that the Amplify client library sends when specifying I'm not making these requests via the Amplify client -- I'm setting the However, to answer your question, the "aws_project_region": "us-east-1",
"aws_appsync_graphqlEndpoint": "https://xxxxxxxxxx.appsync-api.us-east-1.amazonaws.com/graphql",
"aws_appsync_region": "us-east-1",
"aws_appsync_authenticationType": "AWS_LAMBDA", To clarify:
|
Using the browser developer tools, could you check whether the request headers contains the key |
@sundersc I can verify that the Only
Same is true for requests sent from the app (we use a third party graphql library, not the Amplify client). Could you show me what the Amplify client sends when specifying the AWS_LAMBDA authentication mode? |
@sundersc I believe the lambda authorization was configured as follows:
In this setup, I was able to access the GraphQL API with an API Key (using the Now, after I migrated to Transformer V2, I've done the following steps to move to using Lambda as the sole authorization mode in the app:
|
I'm still unable to reproduce the issue on my end. Could you please zip the |
@sundersc, sure, I've sent it over just now. |
@jevakallio - AppSync confirmed that this is a bug and working on a fix. To mitigate the issue, send |
@sundersc thank you! I can also confirm that returning |
Awesome! I'm closing this issue in favor of a support ticket for AppSync team to track the issue. Feel free to reopen if required. |
Before opening, please confirm:
How did you install the Amplify CLI?
npm
If applicable, what version of Node.js are you using?
16.13.0
Amplify CLI Version
7.6.24
What operating system are you using?
Mac
Did you make any manual changes to the cloud resources managed by Amplify? Please describe the changes made.
No
Amplify Categories
api
Amplify Commands
Not applicable
Describe the bug
N/A
Expected behavior
Note: This issue is similar to aws-amplify/amplify-category-api#100 (except we are using Lambda Authorizer instead of IAM). Based on debugging, these two issues appear to have a different root causes, so creating a new issue instead of tacking on to that one.
TL;DR;
We've recently migrated to GraphQL Transformer V2.
We are trying to disable API Key access to our API in favour or custom Lambda authorizer function, but we are receiving the following error for all queries/mutations:
Longer version
Prior to disabling API key authentication, we were using a combination of
@auth(rules: [{ allow: public }]) @aws_lambda
on all our@model
types, which worked. But after disabling API Key access in the project, we are not able to useallow: public
due to the following error when runningamplify api gql-compile
oramplify push
:Instead, I am trying to use
@auth(rules: [{ allow: custom }])
to decorate our@model
types as instructed in the Custom authorization rule documentation. For example:(The documentation does not specify that we should retain the
@aws_lambda
AppSync decorator, but I've tried it with and without, and we get the same result)Now, calling the following query:
Will return:
This is the API instance configuration from
amplify/backend-config.json
, whereAppsyncAuthorization
refers to a lambda deployed within the same Amplify project. These configurations seem to applied correctly (see screenshot a bit later in this issue).Digging a bit into the generated VTL resolvers for the query
QuerygetUserauth0Function
, I see that there's a check like this:I'm assuming that this line is intended to bypass the default authorization requirements and pass the authorization over to the Lambda authorizer. So I logged the output of
$util.authType()
, and the returned value is:Double checking in the AppSync console, the authorization mode is indeed set to Lambda Authorization as per the Amplify config:
Looking at Resolver Util Reference documentation, "Lambda Authorization" is not one of the valid return values for
$util.authType()
.So, what's going on here?
@auth
directive?And most importantly, how can I get around this problem?
Reproduction steps
See issue description.
GraphQL schema(s)
Relevant parts of schema:
Additional information
The text was updated successfully, but these errors were encountered: