使用Steam连接Steam的OpenId OmniAuth gem会出现"invalid_credentials"错误

Tec*_*noh 5 ruby-on-rails omniauth steam-web-api steam ruby-on-rails-5

我正在尝试使用omn​​iauth-steam gem通过Steam连接用户并检索用户的ID64.我正在使用本地网络上的服务器运行Ruby on Rails 5.0.1,运行Apache和Passenger.每当我尝试连接到/ auth/steam时,我都会被"连接"按钮重定向到Steam网页(我已经登录).当我单击按钮时,我会收到一个错误页面,其中包含"invalid_credentials"消息.我登录Steam并可以毫无问题地浏览网站.那条消息来自哪里?我怎样才能解决这个问题?到目前为止,这是我的代码.

Omniauth初始化程序:

# config/initializers/omniauth.rb
Rails.application.config.middleware.use OmniAuth::Builder do
  provider :steam, Rails.application.secrets.steam_web_api_key
end
Run Code Online (Sandbox Code Playgroud)

控制器:

skip_before_filter :verify_authenticity_token, :only => :auth_callback

def index
end

def auth_callback
    auth = request.env['omniauth.auth']
    session[:current_user] = {
        :nickname => auth.info['nickname'],
        :image => auth.info['image'],
        :uid => auth.uid
    }
    redirect_to root_url
end
Run Code Online (Sandbox Code Playgroud)

查看:

<p><%= link_to image_tag("http://cdn.steamcommunity.com/public/images/signinthroughsteam/sits_large_noborder.png"), '/auth/steam' %></p>
Run Code Online (Sandbox Code Playgroud)

路线:

get 'admin/index'
post 'auth/steam/callback' => 'admin#auth_callback'

root 'admin#index'
Run Code Online (Sandbox Code Playgroud)

错误堆栈:

invalid_credentials

Extracted source (around line #25):
23    def raise_out!
24      fail(env['omniauth.error'] || OmniAuth::Error.new(env['omniauth.error.type']))
25
26    end
27
28    def redirect_to_failure

omniauth (1.3.1) lib/omniauth/failure_endpoint.rb:25:in `raise_out!'
omniauth (1.3.1) lib/omniauth/failure_endpoint.rb:20:in `call'
omniauth (1.3.1) lib/omniauth/failure_endpoint.rb:12:in `call'
omniauth (1.3.1) lib/omniauth/strategy.rb:479:in `fail!'
omniauth-openid (1.0.1) lib/omniauth/strategies/open_id.rb:80:in `callback_phase'
omniauth (1.3.1) lib/omniauth/strategy.rb:227:in `callback_call'
omniauth (1.3.1) lib/omniauth/strategy.rb:184:in `call!'
omniauth (1.3.1) lib/omniauth/strategy.rb:164:in `call'
omniauth (1.3.1) lib/omniauth/builder.rb:63:in `call'
rack (2.0.1) lib/rack/etag.rb:25:in `call'
rack (2.0.1) lib/rack/conditional_get.rb:25:in `call'
rack (2.0.1) lib/rack/head.rb:12:in `call'
rack (2.0.1) lib/rack/session/abstract/id.rb:222:in `context'
rack (2.0.1) lib/rack/session/abstract/id.rb:216:in `call'
actionpack (5.0.1) lib/action_dispatch/middleware/cookies.rb:613:in `call'
activerecord (5.0.1) lib/active_record/migration.rb:553:in `call'
actionpack (5.0.1) lib/action_dispatch/middleware/callbacks.rb:38:in `block in call'
activesupport (5.0.1) lib/active_support/callbacks.rb:97:in `__run_callbacks__'
activesupport (5.0.1) lib/active_support/callbacks.rb:750:in `_run_call_callbacks'
activesupport (5.0.1) lib/active_support/callbacks.rb:90:in `run_callbacks'
actionpack (5.0.1) lib/action_dispatch/middleware/callbacks.rb:36:in `call'
actionpack (5.0.1) lib/action_dispatch/middleware/executor.rb:12:in `call'
actionpack (5.0.1) lib/action_dispatch/middleware/remote_ip.rb:79:in `call'
actionpack (5.0.1) lib/action_dispatch/middleware/debug_exceptions.rb:49:in `call'
web-console (3.4.0) lib/web_console/middleware.rb:135:in `call_app'
web-console (3.4.0) lib/web_console/middleware.rb:20:in `block in call'
web-console (3.4.0) lib/web_console/middleware.rb:18:in `catch'
web-console (3.4.0) lib/web_console/middleware.rb:18:in `call'
actionpack (5.0.1) lib/action_dispatch/middleware/show_exceptions.rb:31:in `call'
railties (5.0.1) lib/rails/rack/logger.rb:36:in `call_app'
railties (5.0.1) lib/rails/rack/logger.rb:24:in `block in call'
activesupport (5.0.1) lib/active_support/tagged_logging.rb:69:in `block in tagged'
activesupport (5.0.1) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (5.0.1) lib/active_support/tagged_logging.rb:69:in `tagged'
railties (5.0.1) lib/rails/rack/logger.rb:24:in `call'
sprockets-rails (3.2.0) lib/sprockets/rails/quiet_assets.rb:13:in `call'
actionpack (5.0.1) lib/action_dispatch/middleware/request_id.rb:24:in `call'
rack (2.0.1) lib/rack/method_override.rb:22:in `call'
rack (2.0.1) lib/rack/runtime.rb:22:in `call'
activesupport (5.0.1) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
actionpack (5.0.1) lib/action_dispatch/middleware/executor.rb:12:in `call'
actionpack (5.0.1) lib/action_dispatch/middleware/static.rb:136:in `call'
rack (2.0.1) lib/rack/sendfile.rb:111:in `call'
railties (5.0.1) lib/rails/engine.rb:522:in `call'
/usr/lib/ruby/vendor_ruby/phusion_passenger/rack/thread_handler_extension.rb:97:in `process_request'
/usr/lib/ruby/vendor_ruby/phusion_passenger/request_handler/thread_handler.rb:152:in `accept_and_process_next_request'
/usr/lib/ruby/vendor_ruby/phusion_passenger/request_handler/thread_handler.rb:113:in `main_loop'
/usr/lib/ruby/vendor_ruby/phusion_passenger/request_handler.rb:416:in `block (3 levels) in start_threads'
/usr/lib/ruby/vendor_ruby/phusion_passenger/utils.rb:113:in `block in create_thread_and_abort_on_exception'
Run Code Online (Sandbox Code Playgroud)

Tec*_*noh 1

事实证明,在这种情况下,是因为运行脚本的服务器和 Steam 的服务器之间存在时间差。我的服务器上的日期/时间有几分钟的偏差,一旦我纠正了时间差异,错误消息就消失了,登录过程成功了。