开发者

Ruby on Rails: how do I make an http password protected sub domain?

开发者 https://www.devze.com 2023-01-27 05:29 出处:网络
I want a subdomain like... admin.example.com but I want it to require a user and password.开发者_StackOverflow中文版 Like... the kind that uses teh browser\'s interface, rather than a database backed

I want a subdomain like... admin.example.com

but I want it to require a user and password.开发者_StackOverflow中文版 Like... the kind that uses teh browser's interface, rather than a database backed authentication system.

what are some good methods of doing this?


It's fairly simple:

# products_controller.rb
before_filter :authenticate

protected

def authenticate
  authenticate_or_request_with_http_basic do |username, password|
    username == "foo" && password == "bar"
  end
end

See: http://railscasts.com/episodes/82-http-basic-authentication


Write a small rack application. Both checking if its the correct subdomain and enforcing basic auth can be done easily.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号