我用 WePay 策略(https://github.com/intridea/omniauth)设置了 Omniauth。获得授权时,它会进行v2/oauth2/token
四次调用(穿插调用),但会在变量/v2/user
中的第一个访问令牌上返回。env["omniauth.auth"]
这会导致回调的加载时间过长,并且在稍后尝试执行 API 调用时出现“access_token revoked”错误。
我完全搞不懂为什么会这样。我已经尝试禁用回调之后的每个方法,所以我很确定这发生在 Omniauth 本身中,而不是我的应用程序(在 Rails 中,顺便说一句)。
这是我的omniauth.rb
初始化文件:
require "omniauth/strategies/wepay"
OmniAuth.config.logger = Rails.logger
Rails.application.config.middleware.use OmniAuth::Builder do
provider :wepay, ENV['WEPAY_STAGE_APP_ID'], ENV['WEPAY_STAGE_SECRET']
provider :twitter, ENV['TWITTER_CONSUMER_KEY'], ENV['TWITTER_CONSUMER_SECRET']
provider :facebook, ENV['FACEBOOK_APP_ID'], ENV['FACEBOOK_APP_SECRET']
end
相关路线:
match 'auth/wepay/callback', to: 'sessions#wepay'
match 'auth/failure', to: redirect('/organization')
会话控制器(尽管我有理由相信循环在它被调用之前就已经发生了):
class SessionsController < ApplicationController
before_filter :get_all_organizations
before_filter :authorize_current_organization
def wepay
current_user.from_omniauth(env["omniauth.auth"])
if @organization.wepay_account_id? == false
@organization.create_wepay_account(current_user)
end
redirect_to transactions_path, notice: 'Login successful.'
end
end
我日志的相关部分:
Started GET "/auth/wepay/" for 127.0.0.1 at 2012-08-26 17:40:18 -0700
(wepay) Request phase initiated.
Started GET "/auth/wepay/callback?code=XXXXX&state=XXXXX" for 127.0.0.1 at 2012-08-26 17:40:25 -0700
(wepay) Callback phase initiated.
Connected to NewRelic Service at collector-6.newrelic.com
Processing by SessionsController#wepay as HTML
Parameters: {"code"=>"XXXXX", "state"=>"XXXXX"}
我在调试时遇到了困难,但 New Relic 确实显示 548ms 花费在 中sessions#wepay
,而 261ms 花费在Net::HTTP[stage.wepayapi.com]: POST
. 我不知道这是否表明了什么。