Ruby on rails 使用Omniauth注册时防止重定向
我正在使用Omniauth对JSON API进行身份验证 提交到/auth/identity/register后,我希望返回结果,而不重定向用户。如何做到这一点 为了允许OmniAuth::Strategies::Identity.registration_阶段接受JSON数据,我将第一行替换为以下内容,对其进行了monkey修补:Ruby on rails 使用Omniauth注册时防止重定向,ruby-on-rails,json,omniauth,Ruby On Rails,Json,Omniauth,我正在使用Omniauth对JSON API进行身份验证 提交到/auth/identity/register后,我希望返回结果,而不重定向用户。如何做到这一点 为了允许OmniAuth::Strategies::Identity.registration_阶段接受JSON数据,我将第一行替换为以下内容,对其进行了monkey修补: if !env["rack.input"].nil? attributes = JSON.parse(request.env["rack.inp
if !env["rack.input"].nil?
attributes = JSON.parse(request.env["rack.input"].read)
else
attributes = (options[:fields] + [:password, :password_confirmation]).inject({}){|h,k| h[k] = request[k.to_s]; h}
end
这可以很好地工作,如果失败,我将设置为_failed _registration来处理它-但是如果成功,我只想返回一个带有结果的200,而不是重定向
我已经尝试按如下方式进行monkeypatch OmniAuth::Strategies::Identity.callback_阶段,但没有成功(即使它正在打印我的puts,它仍然重定向):
shioyama-我希望这对你有帮助,这就是我正在做的
module OmniAuth
module Strategies
# The identity strategy allows you to provide simple internal
# user authentication using the same process flow that you
# use for external OmniAuth providers.
class Identity
def registration_phase
if env['CONTENT_TYPE'].match(/x-www-form/).nil?
attributes = JSON.parse(request.env["rack.input"].read)
else
attributes = (options[:fields] + [:password, :password_confirmation]).inject({}){|h,k| h[k] = request[k.to_s]; h}
end
@identity = model.create(attributes)
if @identity.persisted?
env['PATH_INFO'] = callback_path
callback_phase
else
if options[:on_failed_registration]
self.env['omniauth.identity'] = @identity
options[:on_failed_registration].call(self.env)
else
registration_form
end
end
end
end
end
end
刚刚谈到同一个问题,运气好吗?
module OmniAuth
module Strategies
# The identity strategy allows you to provide simple internal
# user authentication using the same process flow that you
# use for external OmniAuth providers.
class Identity
def registration_phase
if env['CONTENT_TYPE'].match(/x-www-form/).nil?
attributes = JSON.parse(request.env["rack.input"].read)
else
attributes = (options[:fields] + [:password, :password_confirmation]).inject({}){|h,k| h[k] = request[k.to_s]; h}
end
@identity = model.create(attributes)
if @identity.persisted?
env['PATH_INFO'] = callback_path
callback_phase
else
if options[:on_failed_registration]
self.env['omniauth.identity'] = @identity
options[:on_failed_registration].call(self.env)
else
registration_form
end
end
end
end
end
end