Skip to content

Omniauth path_prefix being set wrong for app at Sub-uri #875

Closed

Description

@mikeauclair

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

Activity

  1. josevalim commented on Feb 23, 2011

    @josevalim
    Contributor

    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?

  2. mikeauclair commented on Feb 23, 2011

    @mikeauclair
    Author

    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.

  3. mikeauclair commented on Feb 23, 2011

    @mikeauclair
    Author

    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.)

  4. josevalim commented on Feb 23, 2011

    @josevalim
    Contributor

    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"

  5. josevalim commented on Feb 23, 2011

    @josevalim
    Contributor

    Ok, so we need to fix both Devise and Omniauth. :)

  6. mikeauclair commented on Feb 23, 2011

    @mikeauclair
    Author

    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.

  7. josevalim commented on Feb 23, 2011

    @josevalim
    Contributor

    Ok, thanks!

  8. graywh commented on Mar 4, 2011

    @graywh

    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.

  9. josevalim commented on Mar 4, 2011

    @josevalim
    Contributor

    Interesting, do you think you can provide a failing test case to devise suite or publish a small application on Github?

  10. mikeauclair commented on Mar 4, 2011

    @mikeauclair
    Author

    In config/initializers/devise.rb
    try changing:
    config.omniauth :myldap
    to
    config.omniauth :myldap, :path_prefix => '/prefix/users/auth'

  11. josevalim commented on Mar 4, 2011

    @josevalim
    Contributor

    Yeah, that is a quick fix. But I think we should fix it in omniauth for real this time. :)

  12. josevalim commented on Mar 4, 2011

    @josevalim
    Contributor

    Try this instead: config.omniauth :myldap, :request_path => '/prefix/users/auth'

  13. graywh commented on Mar 4, 2011

    @graywh

    Yeah, I discovered yesterday that overriding request_path does work.

  14. graywh commented on Mar 4, 2011

    @graywh

    And request_path can't be passed as an option, AFAIK.

  15. josevalim commented on Mar 4, 2011

    @josevalim
    Contributor

    It can on latest omniauth according to the source code. :)

  16. graywh commented on Mar 4, 2011

    @graywh

    nevermind, i'm blind :-/

  17. graywh commented on Mar 4, 2011

    @graywh

    But doesn't it have to be "/prefix/user/auth/provider"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions