Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow HTTP authentication (for an API, etc) #34

Closed
karmi opened this issue Aug 1, 2009 · 10 comments
Closed

Allow HTTP authentication (for an API, etc) #34

karmi opened this issue Aug 1, 2009 · 10 comments
Labels

Comments

@karmi
Copy link

karmi commented Aug 1, 2009

Hi,

I needed to have HTTP authentication on current project using Clearance, and discovered Clearance does not provide it. I implemented it as following patch:

http://gist.github.com/159604

Does adding feature like this make sense to you?

(Note: I've tried to implement it directly to Clearance, but have not found an obvious way where to put the tests. I could not persuade AccountsControllerTest to have access to User or Factory(:email_confirmed_user) etc and had to give up.)

@booch
Copy link

booch commented Aug 22, 2009

+1 This would be a helpful feature to add to Clearance.

@joergbattermann
Copy link

Yep agreed. Clearance is awesome, but no http auth is a showstopper for most of my customers' projects. +1

@pius
Copy link

pius commented Oct 23, 2009

+1

@croaky
Copy link
Contributor

croaky commented Nov 4, 2009

@karmi
Copy link
Author

karmi commented Nov 7, 2009

Hello Dan,

I think the main reason here is convenience. When it's built-in, we get HTTP-Auth for non-HTML requests automatically, quite transparently, and stupidly easy.

To use Rack::Auth::Basic middleware for this in Rails, one has to do (and please correct me if I'm mistaken!!):

  • Add the middleware somewhere in the stack
  • Intercept calls to non-HTML requests, do the ::User.authenticate(login, password) authentication,
  • somehow (?) set the @_current_user variable to be available for controllers

Again, correct me if I'm wrong. I haven't tried it, I am just thinking aloud.

Of course, I completely understand the need to keep Clearance lean. I just think the lack of HTTP-Auth for non-HTML requests is something which puts unneccessary burden on the library users -- and more so, if they're beginners etc.

(Now, Sinatra is obviously another story. You expect to operate much closer to the metal.)

Karel

@croaky
Copy link
Contributor

croaky commented Feb 17, 2010

We're going to pass on this patch. Thanks for the effort but we don't think it belongs in Clearance. We're comfortable (and prefer the explicitness of) using Rack::Auth for our APIs:

use Rack::Auth::Basic do |username, password|
username == 'foo' and password == 'bar'
end

Thanks again.

@karmi
Copy link
Author

karmi commented Feb 17, 2010

Hi, sure, understood! In that case I think some info or short tutorial in Clearance docs about how to concretely implement HTTP based auth in a Clearance application would be great. (The usual use-case is something like "give me JSON export with recent photos for the authenticated user", etc)

@croaky
Copy link
Contributor

croaky commented Feb 17, 2010

Definitely. I've tagged this issue as 'docs' and will try to get to it in the next few days.

@karmi
Copy link
Author

karmi commented Dec 26, 2010

I've packaged HTTP Auth for Clearance as a gem: https://github.com/karmi/clearance_http_auth (It works by setting an env variable in middleware and overloading current_user to read it.)

@croaky
Copy link
Contributor

croaky commented Dec 26, 2010

Very nice. Well done!

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants