when using 'devise' gem, I get a No route matches [GET] "/auth/shopify", which disappear after I turn off the 'devise'
theoretically the devise use different path for urls:
user_omniauth_authorize_path GET|POST /users/auth/:provider(.:format) users/omniauth_callbacks#passthru {:provider=>/facebook/}
user_omniauth_callback_path GET|POST /users/auth/:action/callback(.:format) users/omniauth_callbacks#:action
I did not figure out a workaround in routes yet, I was wonder if someone can help me, please
Are you using devise with Shopify users? The gem wasn't really built to do that and I believe you'll need to connect the omniauth provider right to devise.
I need more details to figure out what is wrong - can you please describe your setup and what you are trying to do?
I'm also not sure at this point if this is really an issue with this gem, so I may close this and we can move the discussion to the Shopify forums.
Hi, Kevin
Entire shopify_app does not work with devise. All it needs is to add gem 'devise' to Gemfile and the session seems broken.
I gave up to devise omniauth and used directly omniauth-facebook with a custom model to save data.
Best regards,
Razvan
Also, makes sense, is not an issue with this gem, I just put it here, maybe I can get some clues, which I already did, I understood now
R
Cool - both this gem and devise are both engines so they are probably conflicting but it would take some work to figure out the best way to have them play nice. We don't use devise with this gem internally so I can't really say what all would be required.
glad you got it figured out.
The same problem here but I don't know what's the reason. Can anyone give some clue about this issue? @avra911 I really need your help here because my project is very urgent. If you have some time, can I ask for some help from you about this problem? Thanks soooo much!
The engines are likely conflicting with each other. This engine wasn't designed to be used with devise so I don't know where the issue is. I'm not super familiar with devise so I can't offer any more help.
Hi, @ysyyork!
This is a pretty old issue and I do not think was done something in this direction.
I remember I gave up using devise on the project I was involved, because was not really necessary after all. The ideas was to receive facebook session, store in database and create/login shopify user via api using multipass (which is available in a plus paid account).
You can create your own user session table I suppose in your rails application. Check if you really need devise in your project , try to find another solution to your needs and most important take your time, while I guess is better to succeed slow than to fail fast :)
Best,
Razvan
Echoing what @avra911 said you probably don't really need devise if you are building a Shopify app since this gem takes care of all the Shopify auth for you.
If you are adding users internally to your Shopify app and thats what you want devise for then that makes sense but its going to be a tricky devise setup since its not standard usage. For the issue I would look into disabling devise omniauth since that looks like where the conflict is coming from.
You'll probably be better off implementing your own versions of users inside your app or maybe using something more light weight like thoughtbot/clearance
yeah agreed, devise is definitely overkill given that you get the Shopify oauth stuff for "free", which lets you know that a user is authenticated (has the app installed in their shop). Then it's up to you/your app to provide the logic to determine whether the user is authorized to use your app (typically do they have an active recurring application charge, etc)
@avra911 I think the problem occurred because you are using devise omniauthable module, and omniauth builder middleware at the same time, and devise's overwrite the omniauth builder for Shopify. My solution is not using devise's omniauthable module, and set up additional omniauth strategy manually. Correct me if you are not using the devise's omniauthable.
Thanks @andychong1996 I faced same issue and fixed. Written a blog post and gist so now don't have to walk the walk again.
@AmitPatel-BoTreeConsulting That was very helpful! Thank you! To get it to work with facebook oauth I had to add the following lines to routes.db:
devise_scope :user do
get '/auth/facebook/callback' => 'users/omniauth_callbacks#facebook'
end
Thanks @andychong1996 I faced same issue and fixed. Written a blog post and gist so now don't have to walk the walk again.
Hi @amitpatelx. I found your blogpost on google and found it immensely helpful. The links here no longer work, so you might want to edit your comment above. I'm adding the updated blogpost link here for anyone else dealing with the same issue. Thank you SO much! 馃檶
@paranoidminotaur You wouldn't happen to have a link to a gist showing how this works, would you? I am going through the process of having authentication on my company website, that then would allow a user to link to their Shopify store as well. Stuck at the moment.
@bryanbeshore I never saw the gist, but I was able to get it sorted out. The biggest takeaway is to not include the devise omniauthable module in your user model, and I had to manually create the omniauth routes explicitly. I don't know if it's necessary but I also mounted the shopify app at /shopify
devise_for :users, controllers: {
sessions: 'users/sessions'
}
devise_scope :user do
match 'auth/twitter', to: 'users/omniauth_callbacks#passthru', via: [:get, :post], as: :user_twitter_omniauth_authorize
match 'auth/twitter/callback(:format)', to: 'users/omniauth_callbacks#twitter', via: [:get, :post], as: :user_twitter_omniauth_callback
match 'auth/facebook', to: 'users/omniauth_callbacks#passthru', via: [:get, :post], as: :user_facebook_omniauth_authorize
match 'auth/facebook/callback(:format)', to: 'users/omniauth_callbacks#facebook', via: [:get, :post], as: :user_facebook_omniauth_callback
match 'auth/google_oauth2', to: 'users/omniauth_callbacks#passthru', via: [:get, :post], as: :user_google_omniauth_authorize
match 'auth/google_oauth2/callback(:format)', to: 'users/omniauth_callbacks#google', via: [:get, :post], as: :user_google_omniauth_callback
end
...
mount ShopifyApp::Engine, at: '/shopify'
I also had issues with installation from the shopify app store when I first enabled oauth. In order to get around that I had to remove a middleware that the shopify_app gem adds in app initialization.
in config/application.rb:
config.middleware.delete(ShopifyApp::SameSiteCookieMiddleware)
This obviously isn't a copy/paste situation for you, but I hope it's helpful.
@paranoidminotaur Thank you so much for the response.
I came across a different solution for this (or if not exactly this, a very closely related issue) so wanted to share.
I have all my omniauth config inside config/initializers/devise.rb. I do not have a config/initializers/omniauth.rb. After adding omniauth-shopify-oauth2 to my Gemfile, I ran into this issue.
Before migrating everything out of devise.rb, I realized that I had not changed this line:
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -149,7 +149,7 @@ class User
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable,
- :omniauthable, omniauth_providers: [:twitter, :linkedin, :pinterest, :facebook, :google_oauth2]
+ :omniauthable, omniauth_providers: [:twitter, :linkedin, :pinterest, :facebook, :google_oauth2, :shopify]
This fixed the problem for me.
Hope that helps someone else!
Most helpful comment
Thanks @andychong1996 I faced same issue and fixed. Written a blog post and gist so now don't have to walk the walk again.