【发布时间】:2012-08-21 13:00:55
【问题描述】:
我为 Omniauth 设置了 WePay 策略 (https://github.com/intridea/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 确实显示在 sessions#wepay 中花费了 548 毫秒,而在 Net::HTTP[stage.wepayapi.com]: POST 中花费了 261 毫秒。我不知道这是否表明了什么。
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-3 oauth oauth-2.0 omniauth