You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Omniauth path_prefix being set wrong for app at Sub-uri #875
Given a Rails 3 app mount at sub-uri /q in passenger (using RackBaseURI /q) with this devise_for:
devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" }, :omniauth_providers => [:blah]
Everything works correctly, except for OmniAuth catching /q/users/auth/blah and redirecting it away to the OmniAuth strategy's authorize_url. If I override the prefix_path getter in my OmniAuth strategy to manually return "/q/users/auth" everything works
Also, devise does not return /q/users/auth, but /users/auth when user_omniauth_authorize_path(:blah) is called. (I forgot I had a fix in place for that as well.)
If what is doing the redirect is OmniAuth, this is an Omniauth bug. When redirecting, they need to check the Rack environmetn as env["SCRIPT_NAME"] and prepend it to the redirect URL. In your case, env["SCRIPT_NAME"] will probably be "/q"
It's fairly easy to set prefix_path for an omniauth strategy, so whether it checks env["SCRIPT_NAME"] or not doesn't really matter to me now. I will submit a new issue for the user_omniauth_authorize_path(:blah) issue for clarity's sake.
I'm having a similar issue with a sub-uri (route /user/auth/provider not recognized), but the callback path is recognized. Overriding omniauth path_prefix causes the authorize path to be recognized, but breaks the callback path.
Using rails 3.0.4, devise HEAD, and omniauth 0.2.0.beta4.
Activity
josevalim commentedon Feb 23, 2011
I don't understand the issue completely.
"Everything works correctly, except for OmniAuth catching /q/users/auth/blah and redirecting it away to the OmniAuth strategy's authorize_url."
What is exactly the OminAuth strategy authorize_url it is redirecting in this case?
mikeauclair commentedon Feb 23, 2011
The authorize_url is an internal OAuth2 server. In https://github.com/plataformatec/devise/blob/master/lib/devise/rails/routes.rb#L271 it sets the path_prefix to /users/auth instead of /q/users/auth.
mikeauclair commentedon Feb 23, 2011
Also, devise does not return /q/users/auth, but /users/auth when user_omniauth_authorize_path(:blah) is called. (I forgot I had a fix in place for that as well.)
josevalim commentedon Feb 23, 2011
If what is doing the redirect is OmniAuth, this is an Omniauth bug. When redirecting, they need to check the Rack environmetn as env["SCRIPT_NAME"] and prepend it to the redirect URL. In your case, env["SCRIPT_NAME"] will probably be "/q"
josevalim commentedon Feb 23, 2011
Ok, so we need to fix both Devise and Omniauth. :)
mikeauclair commentedon Feb 23, 2011
It's fairly easy to set prefix_path for an omniauth strategy, so whether it checks env["SCRIPT_NAME"] or not doesn't really matter to me now. I will submit a new issue for the user_omniauth_authorize_path(:blah) issue for clarity's sake.
josevalim commentedon Feb 23, 2011
Ok, thanks!
graywh commentedon Mar 4, 2011
I'm having a similar issue with a sub-uri (route /user/auth/provider not recognized), but the callback path is recognized. Overriding omniauth path_prefix causes the authorize path to be recognized, but breaks the callback path.
Using rails 3.0.4, devise HEAD, and omniauth 0.2.0.beta4.
josevalim commentedon Mar 4, 2011
Interesting, do you think you can provide a failing test case to devise suite or publish a small application on Github?
graywh commentedon Mar 4, 2011
See https://github.com/graywh/devise-omniauth-sub_uri
mikeauclair commentedon Mar 4, 2011
In config/initializers/devise.rb
try changing:
config.omniauth :myldap
to
config.omniauth :myldap, :path_prefix => '/prefix/users/auth'
josevalim commentedon Mar 4, 2011
Yeah, that is a quick fix. But I think we should fix it in omniauth for real this time. :)
graywh commentedon Mar 4, 2011
See my 3rd message: http://groups.google.com/group/plataformatec-devise/browse_thread/thread/3c14cac22ce90bc8
Overriding path_prefix breaks the callback route being recognized.
josevalim commentedon Mar 4, 2011
Try this instead: config.omniauth :myldap, :request_path => '/prefix/users/auth'
graywh commentedon Mar 4, 2011
Yeah, I discovered yesterday that overriding request_path does work.
graywh commentedon Mar 4, 2011
And request_path can't be passed as an option, AFAIK.
josevalim commentedon Mar 4, 2011
It can on latest omniauth according to the source code. :)
graywh commentedon Mar 4, 2011
nevermind, i'm blind :-/
graywh commentedon Mar 4, 2011
But doesn't it have to be "/prefix/user/auth/provider"