JSON API の認証に Omniauth を使用しています。
/auth/identity/register に送信した後、ユーザーをリダイレクトせずに結果を返したいです。これはどのように行うことができますか?
OmniAuth::Strategies::Identity.registration_phase が JSON データを受け入れられるようにするために、最初の行を次のように置き換えてモンキー パッチを適用しました。
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
これは正常に機能し、失敗した場合は on_failed_registration を設定してそれを処理しますが、成功した場合は、リダイレクトではなく結果で 200 を返したいだけです。
次のように OmniAuth::Strategies::Identity.callback_phase をモンキーパッチしようとしましたが、うまくいきませんでした (プットを出力していてもリダイレクトされます)。
def callback_phase
binding.pry
return fail!(:invalid_credentials) unless identity
if !env["action_dispatch.request.content_type"].to_s.match(/json/).nil?
puts 'Not redirecting because this is JSON.'
return
else
super
end
end