Rails route names hosted in omniauth

I have this in routes.rb:

namespace :api do namespace :v1 do ... devise_for :users, constraints: { format: :json }, :controllers => { :omniauth_callbacks => "auths" } ... end end 

And produces among others, these routes:

 new_api_v1_user_confirmation GET /api/v1/users/confirmation/new(.:format) api/v1/confirmations#new {:format=>:json} GET /api/v1/users/confirmation(.:format) api/v1/confirmations#show {:format=>:json} api_v1_user_omniauth_authorize /users/auth/:provider(.:format) auths#passthru {:provider=>/facebook|twitter|linkedin/, :format=>:json} api_v1_user_omniauth_callback /users/auth/:action/callback(.:format) auths#(?-mix:facebook|twitter|linkedin) {:format=>:json} 

How could you skip the last two routes, for example:

 /api/v1/auth/:provider(.:format) /api/v1/auth/:provider/callback(.:format) 
+6
source share
1 answer

I guess I should translate my comments in response:

For our application, we are doing the pure thing json api, with the base / puppet. To get oAuth working with the device, I deleted it from the application. :) The omniauthable property was removed, which I set and removed omniauth settings from my /devise.rb initializers. Then, after reading on the omniauth page, I implemented it on my own.

My api lives under "/ api / v1"

  • Created a file initializers / omniauth.rb, which lists my providers and keys. For each provider, I also gave it the property: path_prefix => "/ api / v1 / auth".
  • Create a callback controller in my api called api / v1 / oauth_controller.rb. This has been correctly tagged with module names and contains my callback path from services.
  • Updated my routes to configure the callback route for omni. See here: gist.github.com/DaveSanders/5835642
  • In OAuthController.create, I used the details from the provider and went through the main thread "does a social network user exist and has a displayed account?" if so, write them through devise user.sign_in? If not, create a user and then sign it.
  • We redirect back to my application, which then loads the trunk again, after which you can get the registered user data and use it as necessary.

Your implementation may vary, but the way I process my oAuth accounts puts them in my own tables (Twitters, Facebooks, etc.) and then links them to my developer. Thus, I can have several accounts, and the user can log in with any of them.

Also, don't forget to set the twitter / facebook callback to something like:

http://127.0.0.1:3000/api/v1/auth/twitter/callback

to match your route in dev.

Hope this helps others. If I forget the step or you get lost, ask.

+2
source

All Articles