What is a very simple authentication scheme for Sinatra/Rack

后端 未结 4 1403
你的背包
你的背包 2021-01-29 19:57

I am busy porting a very small web app from ASP.NET MVC 2 to Ruby/Sinatra.

In the MVC app, FormsAuthentication.SetAuthCookie was being used to set a persistent cookie wh

4条回答
  •  没有蜡笔的小新
    2021-01-29 20:32

    Todd's answer does not work for me, and I found an even simpler solution for one-off dead simple authentication in Sinatra's FAQ:

    require 'rubygems'
    require 'sinatra'
    
    use Rack::Auth::Basic, "Restricted Area" do |username, password|
        [username, password] == ['admin', 'admin']  
    end
    
    get '/' do
        "You're welcome"
    end
    

    I thought I would share it just in case anyone wandered this question and needed a non-persistent solution.

提交回复
热议问题