Abh*_*mar 5 authentication api ruby-on-rails-3
我正在开发一个将由iphone使用的简单api.在rails中是否有一个简单的身份验证gem(带有令牌身份验证或api密钥),我可以使用http(无https).像启用token_authentication的Devise这样的东西.
Amo*_*ari 11
您可以通过向应用程序控制器添加以下内容来添加http基本身份验证支持
before_filter :http_basic_authenticate
def http_basic_authenticate
authenticate_or_request_with_http_basic do |username, password|
username == "1username" && password == "password1"
end
end
Run Code Online (Sandbox Code Playgroud)
然后试试
curl http://yourdomain.com
=> HTTP Basic: Access denied.
curl --user 1username:password1 http://yourdomain.com
=> result .....
Run Code Online (Sandbox Code Playgroud)