Rack::Auth 与基本 HTTP 身份验证相同吗?
我使用以下代码限制对 Sinatra 应用程序设置页面的访问,代码来自 Sinatra 文档< /a>.
helpers do
def protected!
unless authorized?
response['WWW-Authenticate'] = %(Basic realm="Access restricted")
throw(:halt, [401, "Login incorrect\n"])
end
end
def authorized?
@auth ||= Rack::Auth::Basic::Request.new(request.env)
@auth.provided? && @auth.basic? && @auth.credentials && @auth.credentials == ['admin', 'admin']
end
end
before "/admin" do
protected!
end
Rack::Auth 与 .htaccess 基本身份验证相同吗?
我还可以或应该做些什么来确保它的安全吗?
I'm restricting access to the settings page of my Sinatra app with the following code, from the Sinatra docs.
helpers do
def protected!
unless authorized?
response['WWW-Authenticate'] = %(Basic realm="Access restricted")
throw(:halt, [401, "Login incorrect\n"])
end
end
def authorized?
@auth ||= Rack::Auth::Basic::Request.new(request.env)
@auth.provided? && @auth.basic? && @auth.credentials && @auth.credentials == ['admin', 'admin']
end
end
before "/admin" do
protected!
end
Is Rack::Auth identical to .htaccess basic auth?
Is there anything else I could or should do to secure it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,是一样的。您可以使用摘要式身份验证,或者如果您想坚持使用基本身份验证,您可以确保它使用 SSL。
基本和摘要示例:
https://github.com/ sinatra/sinatra-book-contrib/blob/master/middleware/rack_auth_basic_and_digest.md
HTTPS 与基本示例应用程序:
./config.ru
./app.rb
./helpers/helpers.rb
./controller/admin.rb
./views/admin/index.haml
然后使用 霰弹枪宝石
shotgun config.ru -p 4567
Yes it's the same. You could use Digest auth or if you want to stick with Basic you could make sure it uses SSL.
Basic and Digest example:
https://github.com/sinatra/sinatra-book-contrib/blob/master/middleware/rack_auth_basic_and_digest.md
HTTPS with Basic example app:
./config.ru
./app.rb
./helpers/helpers.rb
./controller/admin.rb
./views/admin/index.haml
Then run the app with the shotgun gem
shotgun config.ru -p 4567