reu / omniauth-steam

Steam authentication strategy for OmniAuth
93 stars 38 forks source link

Help !! NoMethodError undefined method `[]' for nil:NilClass #20

Closed roccia closed 8 years ago

roccia commented 9 years ago

HI there, I'm following this tutorial : https://github.com/bodrovis/Sitepoint-source/tree/master/Dota_on_Rails when I filled out the steam account info , this error came out:

undefined method `[]' for nil:NilClass Extracted source (around line #39): 37
38 def player 39 @player ||= raw_info["response"]["players"].first 40 end 41 42 def steam_id

Rails.root: /home/ubuntu/workspace

Application Trace | Framework Trace | Full Trace omniauth-steam (1.0.3) lib/omniauth/strategies/steam.rb:39:in player' omniauth-steam (1.0.3) lib/omniauth/strategies/steam.rb:17:inblock in class:Steam' omniauth (1.2.2) lib/omniauth/strategy.rb:105:in instance_eval' omniauth (1.2.2) lib/omniauth/strategy.rb:105:inblock in compile_stack' omniauth (1.2.2) lib/omniauth/strategy.rb:104:in each' omniauth (1.2.2) lib/omniauth/strategy.rb:104:ininject' omniauth (1.2.2) lib/omniauth/strategy.rb:104:in compile_stack' (eval):7:ininfo_stack' omniauth (1.2.2) lib/omniauth/strategy.rb:321:in info' omniauth (1.2.2) lib/omniauth/strategy.rb:334:inauth_hash' omniauth (1.2.2) lib/omniauth/strategy.rb:361:in callback_phase' omniauth-openid (1.0.1) lib/omniauth/strategies/open_id.rb:81:incallback_phase' omniauth (1.2.2) lib/omniauth/strategy.rb:227:in callback_call' omniauth (1.2.2) lib/omniauth/strategy.rb:184:incall!' omniauth (1.2.2) lib/omniauth/strategy.rb:164:in call' omniauth (1.2.2) lib/omniauth/builder.rb:59:incall' rack (1.6.1) lib/rack/etag.rb:24:in call' rack (1.6.1) lib/rack/conditionalget.rb:25:incall' rack (1.6.1) lib/rack/head.rb:13:in call' actionpack (4.2.1) lib/action_dispatch/middleware/params_parser.rb:27:incall' actionpack (4.2.1) lib/action_dispatch/middleware/flash.rb:260:in call' rack (1.6.1) lib/rack/session/abstract/id.rb:225:incontext' rack (1.6.1) lib/rack/session/abstract/id.rb:220:in call' actionpack (4.2.1) lib/action_dispatch/middleware/cookies.rb:560:incall' activerecord (4.2.1) lib/active_record/query_cache.rb:36:in call' activerecord (4.2.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:649:incall' activerecord (4.2.1) lib/active_record/migration.rb:378:in call' actionpack (4.2.1) lib/action_dispatch/middleware/callbacks.rb:29:inblock in call' activesupport (4.2.1) lib/active_support/callbacks.rb:88:in call' activesupport (4.2.1) lib/active_support/callbacks.rb:88:in_run_callbacks' activesupport (4.2.1) lib/active_support/callbacks.rb:776:in _run_call_callbacks' activesupport (4.2.1) lib/active_support/callbacks.rb:81:inrun_callbacks' actionpack (4.2.1) lib/action_dispatch/middleware/callbacks.rb:27:in call' actionpack (4.2.1) lib/action_dispatch/middleware/reloader.rb:73:incall' actionpack (4.2.1) lib/action_dispatch/middleware/remote_ip.rb:78:in call' better_errors (2.1.1) lib/better_errors/middleware.rb:59:incall' actionpack (4.2.1) lib/action_dispatch/middleware/debug_exceptions.rb:17:in call' web-console (2.1.2) lib/web_console/middleware.rb:29:incall' actionpack (4.2.1) lib/action_dispatch/middleware/show_exceptions.rb:30:in call' railties (4.2.1) lib/rails/rack/logger.rb:38:incall_app' railties (4.2.1) lib/rails/rack/logger.rb:20:in block in call' activesupport (4.2.1) lib/active_support/tagged_logging.rb:68:inblock in tagged' activesupport (4.2.1) lib/active_support/tagged_logging.rb:26:in tagged' activesupport (4.2.1) lib/active_support/tagged_logging.rb:68:intagged' railties (4.2.1) lib/rails/rack/logger.rb:20:in call' actionpack (4.2.1) lib/action_dispatch/middleware/request_id.rb:21:incall' rack (1.6.1) lib/rack/methodoverride.rb:22:in call' rack (1.6.1) lib/rack/runtime.rb:18:incall' activesupport (4.2.1) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in call' rack (1.6.1) lib/rack/lock.rb:17:incall' actionpack (4.2.1) lib/action_dispatch/middleware/static.rb:113:in call' rack (1.6.1) lib/rack/sendfile.rb:113:incall' railties (4.2.1) lib/rails/engine.rb:518:in call' railties (4.2.1) lib/rails/application.rb:164:incall' rack (1.6.1) lib/rack/lock.rb:17:in call' rack (1.6.1) lib/rack/content_length.rb:15:incall' rack (1.6.1) lib/rack/handler/webrick.rb:89:in service' /usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/webrick/httpserver.rb:138:inservice' /usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/webrick/httpserver.rb:94:in run' /usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/webrick/server.rb:294:inblock in start_thread'

There is a exactly same issues post here : https://github.com/reu/omniauth-steam/issues/10 but I tried their solution, still did not figure out how to make it right. Wish someone can help me! Thank you!

h4b00 commented 9 years ago

If you use rails >= 4.1

here's solution for you ;)

create file omniauth.rb in /conifg/initializers/

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :steam, Rails.application.secrets.STEAM_WEB_API_KEY
end

Get your api key from http://steamcommunity.com/dev/apikey and add line like this to your file /config/secrets.yml in each env.

STEAM_WEB_API_KEY: HERE_YOUR_API_KEY
reu commented 8 years ago

Very nice @h4b00! I will try to make this more clear on the README