Reputation: 1
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.
Upvotes: 0
Views: 69