-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Unable to send graphql accessToken to my lambda authorizer #13922
Comments
Hi! 👋 thanks for raising this issue. I think if you're using the Cognito access token, you should be able to access it from the lambda's event as If you console log authorizationToken, what do you see? The isAuthorized logic in your handler is a Boolean dependent on whether it's not undefined or null. Have you tried overriding the graphql headers with an Authorization header in the Amplify.configure call or client? Lastly, can you share the schema just to be sure of the auth rule on the model? |
Thank you for your reply. So I've tried all 3, but none of them worked. console.log('IDENTITY:', JSON.stringify(event.identity)); const { requestContext: { apiId, accountId, identity } } = event; const identity = event.identity; If i try to send my accessToken from client to lambda as the autorizationToken i can't console log nothing, because im blocked by the lambda, but if i put a random string i can console.log the autorizationToken this is my graphql model/entity : type Documents @model @auth(rules: [{ allow: custom }]) {
id: ID!
path: String
identityId: String
name: String!
description: String
availableForclientIDs: [Clients] @hasMany
entityRelation: [EntityDocumentRelation] @hasMany
} Thanks. |
Hi @domov44 thanks for sharing those excerpts from the docs. It seems like you might be running into a known behavior where the access token is probably being rejected by AppSync because it thinks it might be a Cognito access token. To work around this, you can try adding a random prefix or suffix to the access token in the Authorization header like so: const documents = await client.graphql({
query: listDocuments,
authMode: 'lambda',
authToken: `random ${user.accessToken}`,
}); This should allow it to be detected as an OIDC token instead of a Cognito access token and then your lambda's logic can remove the prefix/suffix and validate it as you normally would. This is the relevant part of that page I'm referring to: Note that you also can't use Let me know if that helps! |
Hi, yes thanks for your help, with this method i'm able to get the accessToken, now i just need to ajust my lambda to use the token by removing the random string. |
Before opening, please confirm:
JavaScript Framework
React
Amplify APIs
GraphQL API
Amplify Version
v6
Amplify Categories
auth, api
Backend
Amplify CLI
Environment information
Describe the bug
I have a dynamodb entity that has a custom auth directive, and I've set this custom auth to an Authorizer lambda
So far so good, my lambda executes well every time I call graphql
But I want to start this lambda with a simple condition that authorizes the Admin group to crud, and another less permissive group to read only (to then go further in the customization).
To do this, I need to send the accessToken in the authtoken in my graphql call, I get the accessToken and send it, but as soon as I send it without even doing anything with the lambda, it rejects me with an error 'Not Authorized to access listDocuments on type Query'.
I tried with the .toString(), and without, nothing to do, I said to myself that maybe the problem came from the character length but no, as soon as I send the token with its .signature (or .randomvalue after the .payload) from the jwt I'm automatically rejected.
Expected behavior
I want to be able to provide my accessToken to my lambda from my graphql calls to authenticate the user.
Reproduction steps
Code Snippet
Log output
aws-exports.js
Manual configuration
No response
Additional configuration
No response
Mobile Device
No response
Mobile Operating System
No response
Mobile Browser
No response
Mobile Browser Version
No response
Additional information and screenshots
The text was updated successfully, but these errors were encountered: