wardencommunity/sinatra_warden

undefined method `authenticated?' for nil:NilClass

Closed this issue · 11 comments

zzak commented

tried adding authorization to my sinatra app using the sinatra_warden gem, setup a new branch for testing. checkout: http://github.com/zacharyscott/tewdew/tree/warden

NoMethodError: undefined method authenticated?' for nil:NilClass /home/zakscott/.rvm/gems/ruby-1.8.7-p299/gems/sinatra_warden-0.3.1/lib/sinatra_warden/sinatra.rb:19:inauthenticated?'
/home/zakscott/.rvm/gems/ruby-1.8.7-p299/gems/sinatra_warden-0.3.1/lib/sinatra_warden/sinatra.rb:59:in authorize!' ./main.rb:69:inGET /tasks'
/home/zakscott/.rvm/gems/ruby-1.8.7-p299/gems/sinatra-1.0/lib/sinatra/base.rb:863:in call' /home/zakscott/.rvm/gems/ruby-1.8.7-p299/gems/sinatra-1.0/lib/sinatra/base.rb:863:inroute'
/home/zakscott/.rvm/gems/ruby-1.8.7-p299/gems/sinatra-1.0/lib/sinatra/base.rb:521:in instance_eval' /home/zakscott/.rvm/gems/ruby-1.8.7-p299/gems/sinatra-1.0/lib/sinatra/base.rb:521:inroute_eval'
/home/zakscott/.rvm/gems/ruby-1.8.7-p299/gems/sinatra-1.0/lib/sinatra/base.rb:500:in route!' /home/zakscott/.rvm/gems/ruby-1.8.7-p299/gems/sinatra-1.0/lib/sinatra/base.rb:497:incatch'
/home/zakscott/.rvm/gems/ruby-1.8.7-p299/gems/sinatra-1.0/lib/sinatra/base.rb:497:in route!' /home/zakscott/.rvm/gems/ruby-1.8.7-p299/gems/sinatra-1.0/lib/sinatra/base.rb:476:ineach'
/home/zakscott/.rvm/gems/ruby-1.8.7-p299/gems/sinatra-1.0/lib/sinatra/base.rb:476:in route!' /home/zakscott/.rvm/gems/ruby-1.8.7-p299/gems/sinatra-1.0/lib/sinatra/base.rb:601:indispatch!'
/home/zakscott/.rvm/gems/ruby-1.8.7-p299/gems/sinatra-1.0/lib/sinatra/base.rb:411:in call!' /home/zakscott/.rvm/gems/ruby-1.8.7-p299/gems/sinatra-1.0/lib/sinatra/base.rb:566:ininstance_eval'
/home/zakscott/.rvm/gems/ruby-1.8.7-p299/gems/sinatra-1.0/lib/sinatra/base.rb:566:in invoke' /home/zakscott/.rvm/gems/ruby-1.8.7-p299/gems/sinatra-1.0/lib/sinatra/base.rb:566:incatch'
/home/zakscott/.rvm/gems/ruby-1.8.7-p299/gems/sinatra-1.0/lib/sinatra/base.rb:566:in invoke' /home/zakscott/.rvm/gems/ruby-1.8.7-p299/gems/sinatra-1.0/lib/sinatra/base.rb:411:incall!'
/home/zakscott/.rvm/gems/ruby-1.8.7-p299/gems/sinatra-1.0/lib/sinatra/base.rb:399:in call' /home/zakscott/.rvm/gems/ruby-1.8.7-p299/gems/rack-1.2.1/lib/rack/showexceptions.rb:24:incall'
/home/zakscott/.rvm/gems/ruby-1.8.7-p299/gems/rack-1.2.1/lib/rack/session/cookie.rb:37:in call' /home/zakscott/.rvm/gems/ruby-1.8.7-p299/gems/sinatra-1.0/lib/sinatra/base.rb:979:incall'
/home/zakscott/.rvm/gems/ruby-1.8.7-p299/gems/sinatra-1.0/lib/sinatra/base.rb:1005:in synchronize' /home/zakscott/.rvm/gems/ruby-1.8.7-p299/gems/sinatra-1.0/lib/sinatra/base.rb:979:incall'
/home/zakscott/.rvm/gems/ruby-1.8.7-p299/gems/rack-1.2.1/lib/rack/lint.rb:48:in _call' /home/zakscott/.rvm/gems/ruby-1.8.7-p299/gems/rack-1.2.1/lib/rack/lint.rb:36:incall'
/home/zakscott/.rvm/gems/ruby-1.8.7-p299/gems/rack-1.2.1/lib/rack/showexceptions.rb:24:in call' /home/zakscott/.rvm/gems/ruby-1.8.7-p299/gems/rack-1.2.1/lib/rack/commonlogger.rb:18:incall'
/home/zakscott/.rvm/gems/ruby-1.8.7-p299/gems/rack-1.2.1/lib/rack/content_length.rb:13:in call' /home/zakscott/.rvm/gems/ruby-1.8.7-p299/gems/rack-1.2.1/lib/rack/handler/webrick.rb:52:inservice'
/home/zakscott/.rvm/rubies/ruby-1.8.7-p299/lib/ruby/1.8/webrick/httpserver.rb:104:in service' /home/zakscott/.rvm/rubies/ruby-1.8.7-p299/lib/ruby/1.8/webrick/httpserver.rb:65:inrun'
/home/zakscott/.rvm/rubies/ruby-1.8.7-p299/lib/ruby/1.8/webrick/server.rb:173:in start_thread' /home/zakscott/.rvm/rubies/ruby-1.8.7-p299/lib/ruby/1.8/webrick/server.rb:162:instart'
/home/zakscott/.rvm/rubies/ruby-1.8.7-p299/lib/ruby/1.8/webrick/server.rb:162:in start_thread' /home/zakscott/.rvm/rubies/ruby-1.8.7-p299/lib/ruby/1.8/webrick/server.rb:95:instart'
/home/zakscott/.rvm/rubies/ruby-1.8.7-p299/lib/ruby/1.8/webrick/server.rb:92:in each' /home/zakscott/.rvm/rubies/ruby-1.8.7-p299/lib/ruby/1.8/webrick/server.rb:92:instart'
/home/zakscott/.rvm/rubies/ruby-1.8.7-p299/lib/ruby/1.8/webrick/server.rb:23:in start' /home/zakscott/.rvm/rubies/ruby-1.8.7-p299/lib/ruby/1.8/webrick/server.rb:82:instart'
/home/zakscott/.rvm/gems/ruby-1.8.7-p299/gems/rack-1.2.1/lib/rack/handler/webrick.rb:13:in run' /home/zakscott/.rvm/gems/ruby-1.8.7-p299/gems/rack-1.2.1/lib/rack/server.rb:213:instart'
/home/zakscott/.rvm/gems/ruby-1.8.7-p299/gems/rack-1.2.1/lib/rack/server.rb:100:in start' /home/zakscott/.rvm/gems/ruby-1.8.7-p299/gems/rack-1.2.1/bin/rackup:4 /home/zakscott/.rvm/gems/ruby-1.8.7-p299/bin/rackup:19:inload'
/home/zakscott/.rvm/gems/ruby-1.8.7-p299/bin/rackup:19
127.0.0.1 - - [02/Aug/2010 22:08:00] "GET /tasks HTTP/1.1" 500 127330 0.2552

what version of warden do you have installed?

zzak commented

warden 0.10.7

I'm having the same issue, on Ruby 1.9.2 dev, Sinatra 1.0, and Warden 0.10.7 as well.

Same issue here, with Ruby 1.8.7, Sinatra 1.0, Warden 0.10.7.

Best way to get around this? Implement your own solution: http://gist.github.com/557436

It doesn't have all of the fancy helpers, etc - but it works nicely for me.

It doesn't have all of the fancy helpers

Isn't it why we use Sinatra in the first place? We could do everything in Rack. Using Warden directly is nice, but it feels like using another language inside my Sinatra project.

Now, that being said, I don't want to be critical here cause I will use this approach too until sinatra_warden is up and working.

Thank you for sharing Nicholas :-)

Same issue with Ruby 1.8.7, Sinatra 1.1.0, Warden 1.0.3

it seems its resulting from the warden middleware not being set i.e. in lib/sinatra_warden/sinatra.rb Sinatra::Warden::Helpers::warden is returning nil

see: https://github.com/jsmestad/sinatra_warden/blob/master/lib/sinatra_warden/sinatra.rb#L21

not sure how to fix this tough, I'm very much a noob to warden and have only used rack via Rails and Sinatra

Got this working by setting default strategy ( https://gist.github.com/107966 )
The sample here sets password strategy, but doesn't set it as default , so add the lines:

use Warden::Manager do |manager|
  manager.default_strategies :password
end

I'm new to warden too and I see all kinds of problems that folks are having with its' implementation.
That is why I'm taking it slower now by reading up on it. This is a very nice start for me. Get it working in Rack first. https://blog.engineyard.com/2015/understanding-rack-apps-and-middleware