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

Posted

技术标签:

【中文标题】使用 Steam OmniAuth gem 连接 Steam 的 OpenId 会出现“invalid_credentials”错误【英文标题】:Connecting with Steam's OpenId with Steam OmniAuth gem gives "invalid_credentials" error 【发布时间】:2017-05-08 12:30:06 【问题描述】:

我正在尝试使用 omniauth-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

控制器

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

查看

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

路线

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

root 'admin#index'

错误堆栈

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'

【问题讨论】:

【参考方案1】:

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

【讨论】:

以上是关于使用 Steam OmniAuth gem 连接 Steam 的 OpenId 会出现“invalid_credentials”错误的主要内容,如果未能解决你的问题,请参考以下文章

自动生成omniauth gem和路由

使用omniauth-twitter / twitter Gem读取Twitter REST API的x-access-Level标头

设计Facebook参数app_id是必需的

Rails Devise Omniauth new_user_registration_url

使用 SAML 连接 GitLab 帐户

Salesforce 错误 - “无效的交叉引用 ID”