[英]Faraday timeout error with omniauth (custom strategy)/doorkeeper
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. 我正在关注这个railscast,并且针对我的具体情况,我遇到了来自omniauth的回调的法拉第超时错误。
Currently I'm using a rails application as an API and backbone as a javascript front-end (on the same application) 目前我正在使用rails应用程序作为API和骨干作为javascript前端(在同一个应用程序中)
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 我决定使用OAuth锁定API并为Omniauth提供自定义策略以作为客户端访问API以及门卫来处理授权逻辑
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
Here is the routing from the routes.rb 这是来自routes.rb的路由
# Oauth urls
match '/auth/twiddle/callback', to: "authentication#connectAPI"
match "/auth/facebook/callback", to: "authentication#loginSocialMedia"
The application never is able to render the connectAPI action, getting COMPLETELY stuck at this point (given by the server logs) 应用程序永远无法呈现connectAPI操作,此时完全陷入困境(由服务器日志指定)
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.
Many of the uids/important information have been omitted from the log. 日志中省略了许多uid /重要信息。
Finally this error is given: 最后给出了这个错误:
Faraday::Error::TimeoutError (Timeout::Error): 法拉第::错误:: TimeoutError(超时::错误):
I hope I have been thorough in my explanation of this problem. 我希望我对这个问题的解释是彻底的。
I don't know why exactly the application seems to be freezing at the callback initiated part of omniauth. 我不知道为什么应用程序似乎在omniauth的回调启动部分冻结。 I have tried updating bundler as a few other stackoverflow questions have pointed me to but it is not working.
我已经尝试更新bundler,因为其他一些stackoverflow问题指出了我,但它无法正常工作。
Perhaps my understanding of OAuth2 is a bit murky. 也许我对OAuth2的理解有点模糊。
If anyone can help me, I would greatly appreciate it 如果有人可以帮助我,我将非常感激
I'm not sure this applies to you been here was my scenario: 我不确定这适用于你在这里是我的情景:
Deadlock - App1 is waiting for an OAuth response from App2, but to complete that response App2 must wait for a response from App1. 死锁 - App1正在等待来自App2的OAuth响应,但要完成该响应,App2必须等待来自App1的响应。
In development mode on Rails (with WebBrick) you can't run multi-threaded, so the request may never be allowed to complete. 在Rails的开发模式下(使用WebBrick),您无法运行多线程,因此可能永远不会允许完成请求。
My solution was to install puma and add to config/environments/development.rb
: 我的解决方案是安装puma并添加到
config/environments/development.rb
:
if ENV["THREADS"]
config.threadsafe!
end
Then when you start the server you'd do THREADS=1 rails s Puma
to test your OAuth stuff. 然后当你启动服务器时,你会做
THREADS=1 rails s Puma
来测试你的OAuth东西。
Or your scenario is completely different and you're actually not communicating between your services. 或者您的方案完全不同,实际上您的服务之间并没有进行通信。 Is your
extra_info
(like Github's /user
) endpoint functioning on the OAuth server? 您的
extra_info
(如Github /user
)端点是否在OAuth服务器上运行? Is your callback actually doing anything? 你的回调真的在做什么吗?
I hope this helps! 我希望这有帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.