Open hirowatari opened 1 month ago
Hi @hirowatari thank you for opening this issue. Have you tried adding type: 'text/csv'
and disposition: 'attachment'
? Also I don't see how this is an issue with the library, could you help me understand that?
Hi @matteodepalo,
Thanks for looking at this.
Have you tried adding type: 'text/csv' and disposition: 'attachment'?
Yes, I've tried that. I've tried quite a few other things as well and would be happy to list those if that's helpful
Also I don't see how this is an issue with the library, could you help me understand that?
Perhaps I should back up and ask a question in return. What I'm trying to accomplish is to have a route protected by the shopify_app
gem. In other places I used ShopifyApp::EnsureHasSession
to do this.
Should I expect ShopifyApp::EnsureHasSession
to work when using send_data
? If so, that's why I thought it was a bug in shopify_app
. If not, perhaps I'm missing a more obvious way to accomplish this.
Thanks again for your attention to this. I've always appreciated Shopify support going back many years.
I haven't seen this issue with send_data
before, so I'm not sure wether ShopifyApp::EnsureHasSession
is creating problems with that. Have you tried removing the line include ShopifyApp::EnsureHasSession
and seeing if it correctly downloads the document?
Have you tried removing the line include ShopifyApp::EnsureHasSession and seeing if it correctly downloads the document?
Yes.
Sorry I wasn't clearer. In the first post I tried to explain that ShopifyApp::EnsureHasSession
caused this, specifically, :activate_shopify_session
. In fact, adding skip_around_action :activate_shopify_session
allows the file to download as expected.
Thank you for your reply @hirowatari , I've flagged this internally so that the team can look at it.
Hey @hirowatari, I noticed in your log that the id_token is not available
[ ShopifyApp | DEBUG | Shop Not Found ] Responding to invalid Shopify ID token: Missing Shopify ID Token
The id_token
is used by EnsureSession
to authenticate the user to ensure this request is coming from a user from the Shopify admin embedded app. Are you using app bridge to make authenticated fetch to your server? That should include the id token as a part of the request header.
Are you using app bridge to make authenticated fetch to your server? That should include the id token as a part of the request header. Yes
I'm not mistaken, the session is there and shown in the first line of the logs.
Started GET "/location_import_files/5/failed_rows_csv?session=67ebebfce25c7668a6ced116994464711faae739888b3c3c773989cc3c10b728&shop=prolo-dev.myshopify.com" for 108.180.124.202 at 2024-09-20 21:13:30 -0700
I believed, the session would need to be there and valid otherwise the request would fail (403). I'm not having an issue with the request failing. The issue is with the request is shown in the browser when it should be downloaded.
I'm concerned that we're not making any progress here. Is there a way I could show you the issue that you would believe? Perhaps with a sample Rails application? Do you have a template or any guidance here?
session=
isn't the parameter the ShopifyApp gem uses to authenticate the user.
The JWT id token that the Gem uses is either in:
id_token=SHOPIFY_ID_TOKEN
ORHere are some references for authentication
Sorry for the confusion about where the token is stored. The authorization header is there as well (see attached)
It does not change between the first request that redirects to patch_shopify_id_token and the request that eventually works but shows the file instead of downloading it.
I'm concerned that we're not making any progress here. Is there a way I could show you the issue that you would believe? Perhaps with a sample Rails application? Do you have a template or any guidance here?
Hmm yea that is quite strange.. If you could provide a sample Rails application that'd be really helpful. Thanks
Hopefully, this repo will show the issue: https://github.com/hirowatari/bug-report-shopify-send-file
Thank you @hirowatari, I can see the issue, I'll bring this to the team and see what's the best solution.
Thanks @zzooeeyy. Was there are progress on this? Or any advice on how to workaround the issue?
Issue summary
Before opening this issue, I have:
shopify_app
version: 22.4.0Linux inni 6.6.50-1-lts #1 SMP PREEMPT_DYNAMIC Sun, 08 Sep 2024 12:27:02 +0000 x86_64 GNU/Linux
log_level: :debug
in my configuration, if applicableGiven a rails app with
and a link to that route:
<a href="/location_import_files/5/failed_rows_csv?session=whatever&shop=prolo-dev.myshopify.com">download</a>
Expected behavior
What do you think should happen?
The file should be downloaded
Actual behavior
What actually happens?
The file is shown in the browser
Steps to reproduce the problem
I think I've detailed it above, but please let me know if you would like more details.
Debug logs
logs where the issue is shown
However if I uncomment
skip_around_action :activate_shopify_session
then file successfully downloads with the following logs