What is a very simple authentication scheme for Sinatra/Rack

后端 未结 4 1415
你的背包
你的背包 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:42

    I used the accepted answer for an app that just had 2 passwords, one for users and one for admins. I just made a login form that takes a password(or pin) and compared that to one that I had set in sinatra's settings (one for admin, one for user). Then I set the session[:current_user] to either admin or user according to which password the user entered and authorized accordingly. I didn't even need a user model. I did have to do something like this:

    use Rack::Session::Cookie, :key => 'rack.session',
                           :domain => 'foo.com',
                           :path => '/',
                           :expire_after => 2592000, # In seconds
                           :secret => 'change_me'
    

    As mentioned in the sinatra documentation to get the session to persist in chrome. With that added to my main file, they persist as expected.

提交回复
热议问题