2013-07-31 62 views
0

我试图让OAuth2用户通过OmniAuth工作为我的末日应用,却看到:
LoadError:无法加载这样的文件 - omniauth,叽叽喳喳

LoadError: cannot load such file -- omniauth-twitter 


我下面的这些例子,虽然他们真是个有点不一致
- http://recipes.sinatrarb.com/p/middleware/twitter_authentication_with_omniauth app.rb
- https://github.com/intridea/omniauth/wiki/Sinatra-Example

的西纳特拉食谱告诉我把Builder中 '配置做' WHI le官方的例子没有,但有'使用Rack :: Session :: Cookie'

我已经在网上寻找好的Sinatra OmniAuth示例,但它似乎赞成Rails。

require "omniauth" 
require "omniauth-twitter" 

# OAuth2 configuration 
use Rack::Session::Cookie 
use OmniAuth::Builder do 
    provider :twitter, 'CONSUMER_KEY', 'CONSUMER_SECRET' 
end 

before do 
# we do not want to redirect to twitter when the path info starts 
# with /auth/ 
    pass if request.path_info =~ /^\/auth\// 

# /auth/twitter is captured by omniauth: 
# when the path info matches /auth/twitter, omniauth will redirect to twitter 
    redirect to('/auth/twitter') unless current_user 
end 

get '/auth/twitter/callback' do 
# probably you will need to create a user in the database too... 
    session[:uid] = env['omniauth.auth']['uid'] 
# this is the main endpoint to your application 
    redirect to('/') 
end 

get '/twitter' do 
    erb "<a href='/auth/twitter'>Sign in with Twitter</a>" 
end 

# Support for OAuth failure 
    get '/auth/failure' do 
    flash[:notice] = params[:message] # if using sinatra-flash or rack-flash 
    redirect '/' 
end 


完整的错误,我得到

Boot Error 
Something went wrong while loading config.ru 
LoadError: cannot load such file -- omniauth-twitter /usr/local/rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `require' 
/usr/local/rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `block in require' 
/usr/local/rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:236:in `load_dependency' 
/usr/local/rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `require' 
/Users/chadsakonchick/Projects/restlessnapkin/app.rb:11:in `<top (required)>' 
config.ru:1:in `require' 
config.ru:1:in `block in inner_app' 
/usr/local/rvm/gems/ruby-1.9.3-p194/gems/rack-1.5.2/lib/rack/builder.rb:55:in `instance_eval' 
/usr/local/rvm/gems/ruby-1.9.3-p194/gems/rack-1.5.2/lib/rack/builder.rb:55:in `initialize' 
config.ru:1:in `new' 
config.ru:1:in `inner_app' 
/usr/local/rvm/gems/ruby-1.9.3-p194/gems/shotgun-0.9/lib/shotgun/loader.rb:112:in `eval' 
/usr/local/rvm/gems/ruby-1.9.3-p194/gems/shotgun-0.9/lib/shotgun/loader.rb:112:in `inner_app' 
/usr/local/rvm/gems/ruby-1.9.3-p194/gems/shotgun-0.9/lib/shotgun/loader.rb:102:in `assemble_app' 
/usr/local/rvm/gems/ruby-1.9.3-p194/gems/shotgun-0.9/lib/shotgun/loader.rb:86:in `proceed_as_child' 
/usr/local/rvm/gems/ruby-1.9.3-p194/gems/shotgun-0.9/lib/shotgun/loader.rb:31:in `call!' 
/usr/local/rvm/gems/ruby-1.9.3-p194/gems/shotgun-0.9/lib/shotgun/loader.rb:18:in `call' 
/usr/local/rvm/gems/ruby-1.9.3-p194/gems/shotgun-0.9/lib/shotgun/favicon.rb:12:in `call' 
/usr/local/rvm/gems/ruby-1.9.3-p194/gems/rack-1.5.2/lib/rack/builder.rb:138:in `call' 
/usr/local/rvm/gems/ruby-1.9.3-p194/gems/rack-1.5.2/lib/rack/handler/webrick.rb:60:in `service' 
/usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service' 
/usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run' 
/usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread' 

回答

1

霰弹枪是罪魁祸首。当我从终端运行“ruby app.rb”时工作的很好,但是用霰弹枪收到错误。

1

它看起来像没有安装omniauth,叽叽喳喳的宝石。例如:

> require "blahblahblah" 
LoadError: cannot load such file -- blahblahblah 

您需要gem install omniauth-twitter,包括在您gemspec如果你使用捆绑,或任何有意义的你的项目。

+0

安装了omniauth-twitter gem。 – csakon

+0

我为上下文添加了完整的错误 – csakon

+0

它是否安装在正确的rvm中?我在/ usr/local/rvm/gems/ruby​​-1.9.3-p194/gems /' –