-
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
v6 - ID Token as Authorization header not working with DataStore/App Sync any more (was working with v5, solution proposed) #12590
Comments
We're facing the same issue in our attempts to migrate out application to v6. |
Related - aws-amplify/docs#6513 |
@nadetastic thx, I opened both issues and also referenced them 😉 But aws-amplify/docs#6513 only faces the lag of documentation. This issue deals with a bug! |
@jgo80, thank you for creating this issue. I've marked this as a bug and there's a fix coming soon. I'll update this issue once it's ready and released. |
Im having the same issue my authorization mode of model is custom lambda and Datastore is using authProvider property to add authorization token for graphql call.. here is my code
|
I am trying to configure Datastore with custom Authentication using AWS_LAMBDA but it's constantly showing unauthorized but on the other hand same auth flow is working fine with App Sync. Need Help!
|
Custom Authentication is not related to ID Token at all, if you digg down into AWS Amplify DataStore configure, you can see that functionAuthProvider is unrelated to this topic. I'd recommend to open a separate issue. |
#12621 same issue I opened here |
@jgo80 - We're currently investigating this, but it was unclear to me if you were using DataStore or the GraphQL API (the title mentions DataStore, but the description mentions the GraphQL API). Thank you! |
@david-mcafee the issue is about DataStore, which is based on AppSync, so the answer is both. I just pointed out where the fix is to be inserted, so there should not be many questions. |
Thank you @jgo80! To clarify my question, DataStore and the GraphQL API are two separate library categories that both use AWS AppSync, so I wanted to see which library category you were using. Can you also let us know what your default auth mode is? Thank you! |
@david-mcafee default auth mode is Cognito. Maybe I did not clearly point this out in the repro description, I thought this was clear by mentioning Pre Token Generation Lambda Trigger Thx for looking into this. The issue (as described) is that the override is not correctly passed down from Amplify.configure > API > GraphQL > headers to Just follow the way back in the code from RealTimeProvider to Configure! (Follow the white rabbit, Neo 😉) |
@jgo80, are you sure this override is still needed for group claims?
For me, the group claims are in the request's idToken even without it. EDIT: And I just realized, you did not mention group claims, just custom claims. So forget about my question. |
@hanna-becker wait, there are different things getting mixed up.
So my mentioned code is the official way to override/pass the idToken to the Authorization header. However the override was not correctly implemented for subscriptions, that's all. Just a missing link. I just want to avoid confusion and mixing up facts. |
@david-mcafee Talking about DataStore vs. GraphQL API - Both actually use the same library |
Yep, you're correct that they both use the I was able to reproduce the problem, and I'm currently working on the fix + tests. Will update this ticket when that is ready. |
@jgo80 - The fix for this issue has been merged, and is now available via the This fix will go out with our next release. |
@david-mcafee I see the subscriptions are working now, ones that collections using But ones with generateClient() started to fail (on unstable package version). I see that it is sending headers without idToken information. I had to include token like this to make it work:
Is it how it should work? Or Amplify.Configure should include by default idToken when configured? |
I apologize but I'm not quite sure I understand your use-case. Could you elaborate a bit more on why you are sending headers to both Unsure if this clarifies things, but whatever is passed to |
@david-mcafee thx for your infos -
Okay, my bad, I now can confirm it is working with the unstable pre-release @david-mcafee |
@jgo80 I think it got into 6.0.6-unstable.e101cea.0+e101cea |
It does this for sync queries that collections use. subscriptions and other queries with |
@jgo80 do you use by chance generateClient()? I see queries still get wrong header when using it. |
No @OperationalFallacy , I'm sorry 🫤 |
@OperationalFallacy - can you elaborate more on your use case - ideally with code snippets, if at all possible? Are you saying that headers passed to Additionally, this change has now been officially released with the latest version of Amplify. |
@ArsSirek - I see that you've closed the DataStore issue linked above as a duplicate of this one - in the ticket, it looks like you're using Amplify version |
Hi @david-mcafee , sure I tried with the unstable version today and it works fine with subscriptions in my case too. |
Glad to hear that, @ArsSirek! And to clarify, there is no need to use unstable any longer, as this fix is now out with the regular release. @OperationalFallacy - If this is still an issue for you, can you please take a look at my previous comment regarding steps to reproduce your issue? Thank you! |
With the fix for this issue released in v6.0.6, we'll close this issue. Let us know if there are further problems regarding this topic. |
@chrisbonifacio @jgo80 this is no longer allowed:
How do I change my Authorization to be idToken then? EDIT: I just realised it was a mistake on my end. I need to add the Grahpql headers to the configure function and not as part of the AWS CONFIG credentials. I overlooked that. |
@mattiLeBlanc
|
Before opening, please confirm:
JavaScript Framework
React Native
Amplify APIs
GraphQL API
Amplify Categories
api
Environment information
Describe the bug
I have some Custom Claims in my ID Token, generated through a Pre Token Generation Lambda Trigger. I need to pass those to API GraphQL. It was working well in V5 but now does not anymore for Subscriptions in V6. I also have the solution, so please read it at the end of my bug description!
In V5 I was doing it like this:
There was no Documentation how to do it in V6, so I figured it out (please also find my request to update the docs aws-amplify/docs#6513 )
So in V6 it is working like this:
Now here is my point regarding the bug:
sync
,queries
andmutations
subscriptions
!** Cause for the bug **
AWSAppSyncRealTimeProvider
** Temporary Resolution / Hotfix for the bug **
In order to make it work BOTH for React Native and the Web I had to patch those three files:
node_modules/@aws-amplify/api-graphql/src/Providers/AWSAppSyncRealTimeProvider/index.ts
node_modules/@aws-amplify/api-graphql/dist/esm/Providers/AWSAppSyncRealTimeProvider/index.mjs
node_modules/@aws-amplify/api-graphql/dist/cjs/Providers/AWSAppSyncRealTimeProvider/index.js
** Change request **
_awsAuthTokenHeader
inAWSAppSyncRealTimeProvider
. There is already a propertygraphql_headers
in TypeAWSAppSyncRealTimeAuthInput
but I think it is not correctly passed down all the way. There also is another variableadditionalCustomHeaders
, I think this is the place where the OptionAPI: {}
is fetched from the Amplify.configure singleton.I hope my description was understandable. Thanks for implementing this soon!
Expected behavior
Passing ID Token to GraphQL Header should work in V6 for Queries, Mutations AND Subscriptions as it worked in V5.
Reproduction steps
Code Snippet
// Put your code below this line.
Log output
aws-exports.js
No response
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
No response
The text was updated successfully, but these errors were encountered: