How to use authentication in Sinatra?

Asked

Viewed 87 times

1

What would be the best way to authenticate in applications built with Ruby/Sinatra? Devise I know doesn’t work. I have tried several tutorials with Warden, but the settings are very complex and confusing in my view. Simple authentication with HTTP would be crazy. Which then is the best way?

1 answer

1


Apparently it has a 'sinatra_warden' Gem that interface between Warden and Sinatra for you https://github.com/jsmestad/sinatra_warden (in English). Example of use, from the module’s own documentation:

require 'sinatra'
require 'sinatra_warden'

class Application < Sinatra::Base
  register Sinatra::Warden

  get '/admin' do
    authorize!('/login') # require session, redirect to '/login' instead of work
    haml :admin
  end

  get '/dashboard' do
    authorize! # require a session for this action
    haml :dashboard
  end
end

Browser other questions tagged

You are not signed in. Login or sign up in order to post.