Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Documentation Error, Authentication

Documentation Error, Authentication

HunkyBill
Shopify Partner
4853 60 569

https://shopify.dev/apps/subscriptions/app-extensions/authenticate

There is a code block about setting up CORS with the Rails App.

 

 

## config/application.rb ##
Rails.application.config.middleware.insert_before(0, Rack::Cors) do
  allow do
    origins '*' # allow access to this api from any domain
    resource '*', # allow all origins access to all resources
      headers: ['authorization', 'content-type', 'context'], # restrict headers to relevant keys
      methods: [:post] # restrict the methods to only the ones expected to be used by the extension
  end
end

 

If you drop this into a Rails App, it throws an error 

 

uninitialized constant Rack::Cors (NameError)

Rails.application.config.middleware.insert_before(0, Rack::Cors) do
                                                         ^^^^^^

 

Custom Shopify Apps built just for you! hunkybill@gmail.com http://www.resistorsoftware.com
Reply 1 (1)

scottshop
Shopify Partner
9 1 1

Make sure you add the `rack_cors` gem to your app. Add this to your gemfile:

 

gem 'rack-cors'


Learn more here: https://github.com/cyu/rack-cors