Created
August 21, 2014 16:02
-
-
Save adamcrown/a7e757759469033584c4 to your computer and use it in GitHub Desktop.
Example Sinatra rack-cas app
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
Oh, my apologizes, the fact is the server I tried to connect to was my university's. And I just discovered that it didn't accept requests from outside the internal network. That's why it didn't work from my computer. Thanks a lot for your help, though.
I'm trying this with rack-cas 0.10.1, ruby 1.9.3p551 and I get the following error:
$ CAS_SERVER="https://mycas.example.com/cas" rackup
/home/stockj3/.rbenv/versions/1.9.3-p551/lib/ruby/gems/1.9.1/gems/rack-cas-0.10.1/lib/rack/cas.rb:12:in `initialize': undefined method `config' for RackCAS:Module (NoMethodError)
from /home/stockj3/.rbenv/versions/1.9.3-p551/lib/ruby/gems/1.9.1/gems/rack-1.6.0/lib/rack/builder.rb:86:in `new'
from /home/stockj3/.rbenv/versions/1.9.3-p551/lib/ruby/gems/1.9.1/gems/rack-1.6.0/lib/rack/builder.rb:86:in `block in use'
from /home/stockj3/.rbenv/versions/1.9.3-p551/lib/ruby/gems/1.9.1/gems/rack-1.6.0/lib/rack/builder.rb:147:in `[]'
from /home/stockj3/.rbenv/versions/1.9.3-p551/lib/ruby/gems/1.9.1/gems/rack-1.6.0/lib/rack/builder.rb:147:in `block in to_app'
from /home/stockj3/.rbenv/versions/1.9.3-p551/lib/ruby/gems/1.9.1/gems/rack-1.6.0/lib/rack/builder.rb:147:in `each'
from /home/stockj3/.rbenv/versions/1.9.3-p551/lib/ruby/gems/1.9.1/gems/rack-1.6.0/lib/rack/builder.rb:147:in `inject'
from /home/stockj3/.rbenv/versions/1.9.3-p551/lib/ruby/gems/1.9.1/gems/rack-1.6.0/lib/rack/builder.rb:147:in `to_app'
from /home/stockj3/Projects/firestone-checker2/config.ru:in `<main>'
from /home/stockj3/.rbenv/versions/1.9.3-p551/lib/ruby/gems/1.9.1/gems/rack-1.6.0/lib/rack/builder.rb:49:in `eval'
from /home/stockj3/.rbenv/versions/1.9.3-p551/lib/ruby/gems/1.9.1/gems/rack-1.6.0/lib/rack/builder.rb:49:in `new_from_string'
from /home/stockj3/.rbenv/versions/1.9.3-p551/lib/ruby/gems/1.9.1/gems/rack-1.6.0/lib/rack/builder.rb:40:in `parse_file'
from /home/stockj3/.rbenv/versions/1.9.3-p551/lib/ruby/gems/1.9.1/gems/rack-1.6.0/lib/rack/server.rb:299:in `build_app_and_options_from_config'
from /home/stockj3/.rbenv/versions/1.9.3-p551/lib/ruby/gems/1.9.1/gems/rack-1.6.0/lib/rack/server.rb:208:in `app'
from /home/stockj3/.rbenv/versions/1.9.3-p551/lib/ruby/gems/1.9.1/gems/rack-1.6.0/lib/rack/server.rb:336:in `wrapped_app'
from /home/stockj3/.rbenv/versions/1.9.3-p551/lib/ruby/gems/1.9.1/gems/rack-1.6.0/lib/rack/server.rb:272:in `start'
from /home/stockj3/.rbenv/versions/1.9.3-p551/lib/ruby/gems/1.9.1/gems/rack-1.6.0/lib/rack/server.rb:147:in `start'
from /home/stockj3/.rbenv/versions/1.9.3-p551/lib/ruby/gems/1.9.1/gems/rack-1.6.0/bin/rackup:4:in `<top (required)>'
from /home/stockj3/.rbenv/versions/1.9.3-p551/bin/rackup:23:in `load'
from /home/stockj3/.rbenv/versions/1.9.3-p551/bin/rackup:23:in `<main>'
@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
I'm sorry, I have to be dumb, but when I launch this code, Firefox telling me this error:
I think I tried all I could, but I don't get it.