Abhay Kumar
Abhay Kumar

Reputation: 1618

Basic Authentication for a rails API

I am developing a simple api which will be used by iphone. Is there a simple authentication gem (with token authentication or api key) in rails which I can use over http(No https). Some thing like Devise with token_authentication enabled.

Upvotes: 8

Views: 8111

Answers (1)

Amol Pujari
Amol Pujari

Reputation: 2349

you can simply add http basic auth support by adding following to application controller

before_filter :http_basic_authenticate

def http_basic_authenticate
  authenticate_or_request_with_http_basic do |username, password|
    username == "1username" && password == "password1"
  end
end

then try

curl http://yourdomain.com
=> HTTP Basic: Access denied.

curl --user 1username:password1 http://yourdomain.com
=> result .....

Upvotes: 16

Related Questions