0

I want to change omniauth callback url dynamically. but I don't know how to change dynamically.

I hope change when put path on view, not config loaded.

like this

- if @is_android
  - callback_path = omniauth_authorize_path(resource_name, "facebook",   callback_path: "/resource/auth/facebook/callback/android")
- else
  - callback_path = omniauth_authorize_path(resource_name, "facebook")

= link_to "sign up with facebook", fb_auth_path

thanks

Opal
  • 81,889
  • 28
  • 189
  • 210

2 Answers2

0

It seems, like this is not possible. omniauth gem works as a Rack middleware, therefore it must be loaded on startup.

The omniauth_authorize_path is basically useless. It only is there, so that you can create paths nicely in a Rails way and you don't have to write link_to 'FB', '/auth/facebook'.

So my best advice it to distinguish the two actions easily in the controller, like I did in my app:

def facebook
  if user_signed_in?
    bind_facebook_account
  else
    login_or_preregister
  end
end
Tomáš Dundáček
  • 1,060
  • 9
  • 8
  • thanks for your comment,but i didnt understand mean... i tried to hook omniauth_authrize_path and change request for facebook. like this ` class MyApp::OmniauthCallbacksController < Devise::OmniauthCallbacksController def facebook if user_signed_in? bind_facebook_account else login_or_preregister end end ` but i cant hook /auth/facebook, so i cant anything request_phase. – y.yokozawa Feb 02 '15 at 03:14
  • If you run `rake routes`, you should see the omniauth routes. If not, follow [this example](https://github.com/plataformatec/devise/wiki/OmniAuth%3A-Overview) in devise Wiki. Anyway, as I can remember, devise uses the "users" prefix for the path. Than it should be `/users/auth/facebook` – Tomáš Dundáček Feb 02 '15 at 07:04
0

I think you can use route constraints in order to decide which route to use as a callback.

Basically the constraint return true or false, having the request as a parameter, so you might do something like:

match "/auth/:provider/callback" => "sessions#android_new", :constraints => IsAndroidConstraint
match "/auth/:provider/callback" => "sessions#new"
guyaloni
  • 4,972
  • 5
  • 52
  • 92