我想动态更改omniauth回调网址。 但我不知道如何动态改变。
我希望在视图中放置路径时更改,而不是配置加载。
像这样- 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
感谢
答案 0 :(得分:0)
看来,这是不可能的。 omniauth
gem用作Rack中间件,因此必须在启动时加载。
omniauth_authorize_path
基本没用。它只在那里,所以你可以用Rails方式很好地创建路径,而且你不必写link_to 'FB', '/auth/facebook'
。
所以我最好建议它在控制器中轻松区分这两个动作,就像我在我的应用程序中所做的那样:
def facebook
if user_signed_in?
bind_facebook_account
else
login_or_preregister
end
end
答案 1 :(得分:0)
我认为你可以使用route constraints来决定使用哪个路由作为回调。
基本上,约束返回true或false,将request
作为参数,因此您可以执行以下操作:
match "/auth/:provider/callback" => "sessions#android_new", :constraints => IsAndroidConstraint
match "/auth/:provider/callback" => "sessions#new"