shopify_app: Oauth error failed_grant_with_invalid_scopes
Issue summary
Before opening this issue, I have:
- [x ] Upgraded to the latest version of the package
shopify_appversion:- Ruby version:
- Operating system:
- Set
log_level: :debugin my configuration, if applicable - Found a reliable way to reproduce the problem that indicates it’s a problem with the package
- Looked for similar issues in this repository
- Checked that this isn’t an issue with a Shopify API
- If it is, please create a post in the Shopify community forums or report it to Shopify Partner Support
I have created a fresh install. I am able to render the page successfully. When I try to install the shop, I get this:
Expected behavior
I left the defaults of:
ShopifyApp.configure do |config|
config.application_name = "My Shopify App"
config.old_secret = ""
config.scope = "read_products" # Consult this page for more scope options:
# https://help.shopify.com/en/api/getting-started/authentication/oauth/scopes
Actual behavior
But it seems to have an issue with the scope.
Steps to reproduce the problem
I ran all the steps to start a new project found in the README.
Debug logs
I do see this on the failed request:
Started POST "/login" for 198.98.126.168 at 2024-05-02 16:40:13 -0400
Cannot render console from 198.98.126.168! Allowed networks: 127.0.0.0/127.255.255.255, ::1
Processing by ShopifyApp::SessionsController#create as HTML
Parameters: {"authenticity_token"=>"[FILTERED]", "shop"=>"easy-tiles-easy-life.myshopify.com"}
Redirected to https://admin.shopify.com/store/easy-tiles-easy-life/oauth/install?client_id=82b530a33880214df01aeb372ca5a890
Completed 302 Found in 2ms (ActiveRecord: 0.0ms | Allocations: 610)
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 1
- Comments: 22 (2 by maintainers)
Hey all! The reason why the CLI works and the generator doesn’t work is because the
shopify_appgem enabled a new installation + authorization method.Previously, your app (behind the scenes and handled in the gem) would need to redirect the user to shopify
admin/oauth/authorizeto initiate the installation process, and shopify redirects the user back to your app’s callback path once the merchant grants permission to install your app. The gem then goes and retrieves an access token which your app can use to make API calls to that shop’s resources. This process happens every-time an access token expires, invalidated, or you need to acquire extra scopes.With the new Shopify managed installation and token exchange authorization flow, you declare the access scopes that your app requires in the
tomlfile and deploy that to Shopify. So when a merchant tries to install your app, Shopify knows what access scopes to request for, and Shopify will handle the installation instead of redirecting to your app to make another redirect to install. And once your app is installed, and Shopify admin loads your app.shopify_appgem’s token exchange logic will exchange that user’s active id token for an access token.This is the best way to handle installation and token acquisition since it involves way less redirects. You can see the videos here comparing the performance improvement.Long story short,
The generator doesn’t configure shopify managed install for your app, but creating the app through the CLI does, that’s why it has different behaviours.
There are a few options:
.tomlto enable Shopify managed install through the CLIOR
Hey @zzooeeyy, thank you for looking into this for us 🙏
I, and I believe I speak for everyone here, have no doubts about this new method being more efficient. We don’t need to be convinced in that 🙃
The problem worth tackling however, is that with the
shopify.app.tomlapproach, we are entering a totally new realm which is not documented in as far asshopify_appgem is concerned.And once a typical Rails developer like myself decides to embark on that quest, they suddenly have to deal with things like not having a
package.jsonfile (and why would someone have it in a Rails app! Only half joking here!!):And okay, it’s an easy problem to solve, but here comes the next one:
I don’t know what comes next as I haven’t yet found a way around the last one.
But does feel like this all should be a little more straightforward, given this is the “official” way to build a Shopify app.
sorry I’ve forgot to mention here that I’ve resolved the issue. I did some debug and found in my
.tomlfile there isI have found if we are using
new_embedded_auth_strategy, we have to remove ☝️ this like from the.tomlfile.After removing this line from
.tomlfile it’s working perfectly!PS it double doesn’t work in Rails 7 because, with importmaps, there is no package.json.
So there are a lot more steps than outlined in the README in order to get this up and running with a hello world.
@zzooeeyy Can you please reopen this issue as a documentation fix?
If you instal this gem an follow the steps outlined, it breaks
I have followed all the instructions given in shopify_app gem Readme and facing the similar issue "Oauth error failed_grant_with_invalid_scopes: The application could not be installed due to invalid scopes requested. "
I created the application directly from shopify partner account rather than cli. anyone knows how can I fix it?
I followed the steps in the gem’s README and got this error as well.
I used the manual option on partners site.
No shopify.app.toml file was created after I ran the generator. If this file is required, I hope the README gets a section explaining this.