本文介绍了与omniauth(自定义策略)法拉第超时错误/守门人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前伴随着这种并为我的具体情况如下上午运行到从omniauth回调法拉第超时错误。

I'm currently following along with this railscast and for my specific situation am running into a Faraday timeout error on the callback from omniauth.

目前我使用的Rails应用程序作为API和骨干作为一个javascript前端(在相同的应用程序)

Currently I'm using a rails application as an API and backbone as a javascript front-end (on the same application)

我决定来锁定使用OAuth的API,并提供了Omniauth自定义策略,访问API作为客户端,以及看门处理授权逻辑

I decided I wanted to lock down the API with OAuth and provided a custom strategy for Omniauth to access the API as a client as well as Doorkeeper to handle the authorization logic

 module OmniAuth
      module Strategies
        class Twiddle < OmniAuth::Strategies::OAuth2
          option :name, :twiddle

          option :client_options, {
            site: "http://localhost:3001",
            authorize_path: "/oauth/authorize"
          }

          uid do
            raw_info["id"]
          end

          info do
            {
              firstName: raw_info["firstName"],
              lastName: raw_info["lastName"],
              email: raw_info["email"]
            }
          end

          def raw_info
            @raw_info ||= access_token.get('/api/v1/user').parsed
          end
        end
      end
    end

我包括用户定制的策略是这样的:

I included the custom strategy like this:

require File.expand_path('lib/omniauth/strategies/twiddle', Rails.root)

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :twiddle, id, secret # Omitting the actual ones for obvious reasons
end

我目前使用的这些宝石在我的包。

I am currently using these gems in my bundle

# OAuth
gem 'oauth2'
gem 'omniauth'
gem 'omniauth-oauth2'
gem 'omniauth-facebook'
gem 'doorkeeper'

下面是我进行身份验证,并尝试以检索适当的访问令牌(也是我卡住)

Here is where I authenticate and attempt to retrive the proper access token (and also where I get stuck)

 def loginParse
    if ( user = User.authenticate( params[:email], params[:password] ) )
      session[:user_id] = user.id
      redirect_to '/auth/twiddle/'
    else
      render :controller => "authentication", :action => "loginIndex", :notice => "Incorrect credentials"
    end
  end

下面是从routes.rb中路由

Here is the routing from the routes.rb

  # Oauth urls
  match '/auth/twiddle/callback', to: "authentication#connectAPI"
  match "/auth/facebook/callback", to: "authentication#loginSocialMedia"

应用程序就能够使conn​​ectAPI动作,得到完全被卡住在这一点上(由服务器日志中给出)

The application never is able to render the connectAPI action, getting COMPLETELY stuck at this point (given by the server logs)

  User Load (0.4ms)  SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 LIMIT 1
  Doorkeeper::Application Load (0.2ms)  SELECT `oauth_applications`.* FROM `oauth_applications` WHERE `oauth_applications`.`uid` = '' LIMIT 1
  CACHE (0.0ms)  SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 LIMIT 1
  Doorkeeper::AccessToken Load (0.3ms)  SELECT `oauth_access_tokens`.* FROM `oauth_access_tokens` WHERE `oauth_access_tokens`.`revoked_at` IS NULL AND `oauth_access_tokens`.`application_id` = 1 AND `oauth_access_tokens`.`resource_owner_id` = 1 ORDER BY created_at desc LIMIT 1
   (0.1ms)  BEGIN
  Doorkeeper::AccessGrant Load (0.2ms)  SELECT `oauth_access_grants`.* FROM `oauth_access_grants` WHERE `oauth_access_grants`.`token` = '' LIMIT 1
  SQL (1.1ms)  INSERT INTO `oauth_access_grants` (`application_id`, `created_at`, `expires_in`, `redirect_uri`, `resource_owner_id`, `revoked_at`, `scopes`, `token`) VALUES (1, '2012-08-08 03:10:31', 600, 'http://localhost:3001/auth/twiddle/callback', 1, NULL, '', '')
   (1.4ms)  COMMIT
Redirected to http://localhost:3001/auth/twiddle/callback?code=a
Completed 302 Found in 12ms (ActiveRecord: 3.7ms)
(twiddle) Callback phase initiated.

许多的UID /的重要信息已经从日志中省略。

Many of the uids/important information have been omitted from the log.

最后给出了这个错误:

法拉第::错误:: TimeoutError(超时::错误):

我希望我在这个问题的解释是透彻。

I hope I have been thorough in my explanation of this problem.

我不知道到底为什么应用程序似乎冻结回调发起omniauth的一部分。我曾尝试更新打捆作为其他一些计算器的问题都指向我,但它不工作。

I don't know why exactly the application seems to be freezing at the callback initiated part of omniauth. I have tried updating bundler as a few other stackoverflow questions have pointed me to but it is not working.

或许是我的OAuth2的理解有点阴暗。

Perhaps my understanding of OAuth2 is a bit murky.

如果有人能帮助我,我将不胜AP preciate它

If anyone can help me, I would greatly appreciate it

推荐答案

我不知道这同样适用于你在这里是我的情况:

I'm not sure this applies to you been here was my scenario:


  • 与数据的应用程序,我们内部的OAuth服务器需要

  • 少一个OAuth的服务器,没有数据就可以了

  • 我们要卸载程序App1到App2的认证部分无需移动数据


  • 程序App1 App2的使用作为验证服务器

  • App2的使用App1的用户数据

死锁 - 程序App1正在等待来自App2的OAuth用户的响应,但要完成
该响应App2的必须等待来自App1的响应。

Deadlock - App1 is waiting for an OAuth response from App2, but to completethat response App2 must wait for a response from App1.

在on Rails的(与WebBrick)不能运行多线程开发模式,因此请求
可能永远不会被允许完成。

In development mode on Rails (with WebBrick) you can't run multi-threaded, so the requestmay never be allowed to complete.

我的解决办法是安装并添加到
配置/环境/ development.rb

My solution was to install puma and add toconfig/environments/development.rb:

if ENV["THREADS"]
  config.threadsafe!
end

然后,当你启动服务器,你会怎么做 THREADS = 1导轨小号彪马来测试你的
OAuth的东西。

Then when you start the server you'd do THREADS=1 rails s Puma to test yourOAuth stuff.

或者你的情况是完全不同的,你其实并没有之间的通信
你的服务。是您的 EXTRA_INFO (如Github上的 /用户)的端点上运行
在OAuth的服务器?是您的回调实际上做什么?

Or your scenario is completely different and you're actually not communicating betweenyour services. Is your extra_info (like Github's /user) endpoint functioning onthe OAuth server? Is your callback actually doing anything?

我希望这有助于!

这篇关于与omniauth(自定义策略)法拉第超时错误/守门人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 06:07