nbudin / devise_openid_authenticatable

OpenID authentication for Devise
MIT License
99 stars 32 forks source link

config.middleware.insert_before(Warden::Manager, Rack::OpenID) throws error #6

Closed douglasrw closed 14 years ago

douglasrw commented 14 years ago

I followed your instructions, but the line config.middleware.insert_before(Warden::Manager, Rack::OpenID) Threw an uninitialized constant error for Warden.

This line: config.middleware.use "Rack::OpenID" from your devise_openid_example does work!

nbudin commented 14 years ago

Have you installed the Devise initializer? If you haven't, Warden won't be available since Devise is what causes it to be loaded.

It's important to use the insert_before line rather than config.middleware.use, because otherwise, the OpenID integration may or may not work correctly (depending on which order Rails decides to load the Rack middleware on startup).

douglasrw commented 14 years ago

Yes, I installed the Devise initializer. Any other ideas?

nbudin commented 14 years ago

Which versions of Rails and Devise are you using?

douglasrw commented 14 years ago

rails 2.3.8 and devise 1.0.8

nbudin commented 14 years ago

OK, after messing with a Rails 2.3 version a bit, I got the following code to work. This is inside environment.rb, in the Initializer block:

require 'warden/manager'
config.middleware.use "Warden::Manager"
config.middleware.insert_before "Warden::Manager", "Rack::OpenID"

Could you try this out and let me know if it works for you?

douglasrw commented 14 years ago

That works. Thanks for your help!

nbudin commented 14 years ago

No problem. I'll update the README and the example app.

douglasrw commented 14 years ago

I spoke too soon.
Adding those lines to the config breaks authentication: When trying to sign_in It always comes back saying 'invalid email or password' . I have database_authenticatable module loaded; and email, password, and identity_url on my form. using the config line from my first post everything works fine, or if I leave out the lines that you added I can at least authenticate to db.

nbudin commented 14 years ago

OK, after some further investigation I think this is not a Rails 2 vs. Rails 3 issue, but rather a Devise 1.0 vs 1.1 issue. Devise 1.0 runs its middleware inclusion commands in an after_initialize block, but Devise 1.1 runs them on engine load.

The upshot of this, I think, is that the insert_before line is necessary for Devise 1.1 and up, and the use line is necessary for Devise 1.0. Since you say authentication works fine with the use line, I'll change the README to recommend this.

Thanks, and sorry for the hassle!

douglasrw commented 14 years ago

thanks for you work on this!