No commit activity in last 3 years
No release in over 3 years
super simple single user auth extension for Sinatra
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

>= 1.1.0
 Project Readme

Sinatra SimpleAuth Extension

Sinatra extension with methods and routes for dealing with simple, single-password authorization

Installation

gem install sinatra-simple-auth

Or via bundler:

gem 'sinatra-simple-auth'

Usage (classic style applications)

# classic_app.rb
require 'rubygems'
require 'sinatra'
require 'sinatra/simple_auth'

enable :sessions
set :password, 'my_cool_password' # set the password
set :home, '/secure/' # where user should be redirected after successful authentication

get '/login/?' do
  erb :login # page with auth form
end

get '/secure/' do
  protected! # protected route, requires auth
  erb :secure
end

get '/' do
  if authorized? # helper method
    "Hello, %username%"
  else
    "Not authorized"
  end
end

Usage (modular style applications)

# modular_app.rb
require 'sinatra/base'
require 'sinatra/simple_auth'

class SinatraModularApp < Sinatra::Base
  enable :sessions
  register Sinatra::SimpleAuth

  set :password, 'hello' # set the password
  set :home, '/' # where user should be redirected after successful authentication

  get '/login/?' do
    erb :login # page with auth form
  end

  get '/secure/' do
    protected! # protected route, requires auth
    erb :secure
  end

  get '/' do
    if authorized? # helper method
      "Hello, %username%"
    else
      "Not authorized"
    end
  end
end