我正在为基于HTTP摘要验证的用户验证用户的ruby应用程序创建一个API。我决定使用Grape API库,因为它使得在Ruby中创建一个API清理器。葡萄文档指出您可以使用摘要式身份验证,如:葡萄API和HTTP摘要验证
http_digest({ :realm => 'Test Api', :opaque => 'app secret' }) do |username|
# lookup the user's password here
{ 'user1' => 'password1' }[username]
end
上面的葡萄实现是Rack::Auth::Digest::MD5
的包装现在也为安全,我读了如RFC 2617中你不需要存储密码为您存储用户名的MD5摘要数据库明文:境界:密码和authticate对抗,所以我创建了一个DataMapper的模式:
class Key
include DataMapper::Resource
property :id, Serial
property :username, String
property :password, String
property :active, Boolean, :default => true
property :created_at, DateTime, :default => DateTime.now
property :updated_at, DateTime
end
现在用我提供什么,我失去了对如何连接这些t我并让它工作。
环顾四周后[机架文摘MD5(https://github.com/rack/rack/blob/master/lib/rack/auth/digest/md5.rb)我想通了,如果'attr_writer:passwords_hashed'设置为“真”,那么它将接受格式为'username:realm:password'的已经哈希密码,这很好,但即时通过Grape API封装器设置该属性有困难。有什么建议么? – ny95 2013-04-05 14:16:08
通过查看葡萄码,您可以将哈希提供给':realm'符号,其中包含':realm,:opaque,:passwords_hashed'键。 。 。没有记录或在葡萄测试,所以有点后门你想要的。我测试了它,但它对我没有用。 – 2013-04-05 15:03:29
我想去尝试一下,看看会发生什么,对于不透明的值,它是什么意思,我可以将它设置为“SecureRandom.hex(15)”吗? – ny95 2013-04-05 15:10:57