简体   繁体   English

如何通过omniauth更改/ auth /:provider路径

[英]How to change /auth/:provider path by omniauth

To remove controller's name I wrote in routes.rb like this. 为了删除控制器的名称,我在routes.rb中这样写。

get "/:user_id/:id", :to => "words#show", :as => :short_user_word

It worked fine, but when I tried to use the path "/auth/:provider/" from omniauth, the first route overwrite omniauth's path. 它工作正常,但是当我尝试使用omniauth的路径“ / auth /:provider /”时,第一个路由会覆盖omniauth的路径。

Omniauth callback url works with following route. Omniauth回调网址可用于以下路由。

get '/auth/:provider/callback' => 'authentications#create'

I want to also set the path "/auth/:provider/", but I don't know how to write right side of this. 我也想设置路径“ / auth /:provider /”,但是我不知道该怎么写。

I've read this question and answer, but I couldn't find how to use :setup option. 我已经阅读了此问题和答案,但找不到如何使用:setup选项。

How to change route of omniauth from /auth/:provider to /myapp/auth/:provider 如何将omniauth的路由从/ auth /:provider更改为/ myapp / auth /:provider

How can I avoid this problem? 如何避免这个问题?

Your routes order must be like below 您的路线顺序必须如下所示

get '/auth/:provider/callback' => 'authentications#create'
get "/:user_id/:id", :to => "words#show", :as => :short_user_word

So first if find /auth/:provider it pick this route otherwise if fetch your normal route 所以首先如果找到/ auth /:provider,则选择此路由,否则,如果获取您的正常路由

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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