我正在使用Spree构建一个ecomm服务,该服务使用了Devise,其中包含来自用户的所有数据,但是我们仅通过API将其用作服务,因此我们有一个应用程序(rails 3.1),客户端/消费者,使用OmniAuth的用户有一个自定义策略,该策略通过Oauth2将请求重定向到提供程序,显示符号为page,然后让请求通过authorize方法,然后整个oauth2流程将正常工作,直到回调,然后用户登录到我们的消费者。
在这部分之前,一切正常,这是我的策略类:
module OmniAuth
module Strategies
class MyStrategy < OAuth2
def initialize(app, api_key = nil, secret_key = nil, options = {}, &block)
client_options = {
:site => CUSTOM_PROVIDER_URL,
:authorize_url => "#{CUSTOM_PROVIDER_URL}/auth/my_provider/authorize",
:token_url => "#{CUSTOM_PROVIDER_URL}/auth/my_provider/access_token"
}
super(app, :onyx_oauth, api_key, secret_key, client_options, &block)
end
protected
def user_data
response = @access_token.get("/auth/my_provider/user.json");
if response.status.to_i == 200
@data ||= MultiJson.decode(response.body);
else
raise 'Service error'
end
end
def request_phase
options[:scope] ||= "read"
super
end
def user_hash
user_data
end
def auth_hash
OmniAuth::Utils.deep_merge(super, {
'uid' => user_data["uid"], …Run Code Online (Sandbox Code Playgroud)