Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 823
Abhay Kumar Avatar asked May 29 '12 10:05

Abhay Kumar


1 Answers

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 .....
like image 147
Amol Pujari Avatar answered Sep 21 '22 23:09

Amol Pujari