我正在开发一个简单的 api,它将被 iphone 使用。Rails 中是否有一个简单的身份验证 gem(带有令牌身份验证或 api 密钥),我可以通过 http(无 https)使用它。像启用了 token_authentication 的设计之类的东西。
问问题
7429 次
1 回答
15
您可以通过将以下内容添加到应用程序控制器来简单地添加 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
然后尝试
curl http://yourdomain.com
=> HTTP Basic: Access denied.
curl --user 1username:password1 http://yourdomain.com
=> result .....
于 2012-05-29T10:59:32.973 回答