0

I want to implement a Shopify feature in Rails 7 where a user can fetch other people's Shopify shop information (orders). I created an app in Shopify partners and grabbed the ID and SECRET key of the app. Set both localhost and Ngrok callback URLs on the APP setting. Then I used Omniauth-Shopify-Oauth2 gem for authentication using Shopify. But it is showing invalid_site encountered when I am trying to log in to Shopify in my Rails 7. What is the solution to that?

config/initializers/devise.rb
config.omniauth :shopify, 'app_id', 'app_secret',
                 scope: 'read_orders'
omniauthcallback_controller.rb

 def shopify
    @user = User.from_omniauth(request.env['omniauth.auth'])

    if @user.persisted?
      sign_in_and_redirect @user, event: :authentication
      set_flash_message(:notice, :success, kind: 'Shopify') if is_navigational_format?
    else
      session['devise.shopify_data'] = request.env['omniauth.auth']
      redirect_to new_user_registration_url
    end
  end
app/models/user.rb

def from_omniauth(auth, signed_in_resource=nil)
    auth_provider = auth.provider
    auth_uid = auth.uid
    Rails.logger.warn ">>>>>>17>>>>>#{auth.inspect}"

    p = AuthProvider.where(provider: auth_provider, user_id: id).first_or_initialize
    p.provider = auth_provider
    p.uid = auth_uid
    p.oauth_token = auth.credentials.token
    p.oauth_expires_at = Time.at(auth.credentials.expires_at)
    p.refresh_token = auth.credentials.refresh_token

Another thing i want to know, if any shop owner installed my app on then i should get his/her shop order information right? I am confused about it.

I was trying to implement shopify omniauth login feature and fetch other people shop order information.

  • Take a look at the code in the Shopify Github, they offer one that just works out of the box. It is called shopify_app. You can easily cop the code from there to see how it all works. Save yourself trouble re-inventing the wheel. – David Lazar Aug 25 '23 at 12:44
  • Shopify_app saved data in the shop table. But I want to save it in another table. Can I modify shopify_app default behavior? @DavidLazar – Md Shafayet Jamil Aug 28 '23 at 15:18
  • It is open source. Do as you please. – David Lazar Aug 28 '23 at 21:48

0 Answers0