Ruby Webrick HTTP Authentication

前端 未结 1 1374
攒了一身酷
攒了一身酷 2021-01-26 01:32

How can I do the same authentication stuff in this page using a subclass like this:

        class Configuration < HTTPServlet::AbstractServlet
        def do_         


        
相关标签:
1条回答
  • 2021-01-26 01:54

    Seems to work OK for me if you do it in pretty much the same style e.g.

    class Configuration < HTTPServlet::AbstractServlet
        def do_GET(req, res)
            HTTPAuth.basic_auth(req, res, "My Realm") {|user, pass|
              # block should return true if
              # authentication token is valid
              user == 'user' && pass == 'topsecret'
            }
            res.body = 
              "Authenticated OK\n"
        end
    end
    

    What is the problem you're having?

    0 讨论(0)
提交回复
热议问题