14

How can I change the route that triggers omniauth from using /auth/:provider to /myapp/auth/:provider ?

I don't want to redirect either, because my server will send anything that's not in /myapp/ to the wrong place.

99miles
  • 10,942
  • 18
  • 78
  • 123

3 Answers3

12

Here is how I did this in the config.ru file. I my case, my provider is CAS.

use OmniAuth::Builder do
  configure do |config|
      config.path_prefix = '/my-app-path/auth'
  end
  provider :cas,  CAS::OPTIONS 
end

Note that CAS::OPTIONS is an array with CAS configuration for omniauth::cas. This seems to work fine. I think you will have to change the omniauth callback too : /auth/:provider/callback should be prefixed to /my-app-path/auth/:provider/callback.

Pierre-Gilles Levallois
  • 4,161
  • 4
  • 28
  • 37
6

You can change it via :setup option

Source: https://github.com/omniauth/omniauth/blob/e9978e377f1ac2b7271e5a8486dfe103a1c1d48d/lib/omniauth/strategy.rb#L304-L307

Sairam
  • 2,708
  • 1
  • 25
  • 34
  • 9
    Thanks! More specifically, I had to add this to my provider: path_prefix: "/myapp/auth" – 99miles Apr 05 '12 at 19:36
  • 1
    the line have change to https://github.com/omniauth/omniauth/blob/master/lib/omniauth/strategy.rb#L296 – tolbard Sep 28 '16 at 04:35
  • New line update over here: https://github.com/omniauth/omniauth/blob/master/lib/omniauth/strategy.rb#L356 – Stan Feb 06 '23 at 15:07
0

Add the following option in your initializer:

option :request_path, 'https://yourdomain.com/auth/yourprovider/callback'

Restart you app server and try!

Rubyrider
  • 3,567
  • 1
  • 28
  • 34