Skip to content

Instantly share code, notes, and snippets.

@adamcrown
Created August 21, 2014 16:02
Show Gist options
  • Save adamcrown/a7e757759469033584c4 to your computer and use it in GitHub Desktop.
Save adamcrown/a7e757759469033584c4 to your computer and use it in GitHub Desktop.
Example Sinatra rack-cas app
# Run with command:
# CAS_SERVER="http://example.com/login" rackup
require 'sinatra/base'
require 'rack/cas'
require 'yaml'
class SinatraRackCASExample < Sinatra::Base
before do
unless session['cas'] && session['cas']['user']
halt 401, 'Unauthorized'
end
end
get '/' do
"Hi #{session['cas']['user']}. You're logged in."
end
end
use Rack::Session::Cookie, key: 'rack.session', path: '/', secret: 'ca1257a7e2ede894900c5a4fb4a9abb40bb4fcbfb08d31bd67522363fba1ff925b5c5101ca9fc69d45b381a3c15ac5e1a854e86de23c789e6b99765cdb3a2451'
use Rack::CAS, server_url: ENV['CAS_SERVER']
run SinatraRackCASExample
@ankane
Copy link

ankane commented May 23, 2015

@jostockley Add require "rack-cas" before require "rack/cas" to fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment