简体   繁体   中英

using omniauth how to change callback path dynamically

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

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

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"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM