lib/rodauth/features/oauth_base.rb in rodauth-oauth-0.9.0 vs lib/rodauth/features/oauth_base.rb in rodauth-oauth-0.9.1

- old
+ new

@@ -2,10 +2,12 @@ require "time" require "base64" require "securerandom" require "net/http" +require "rodauth/version" +require "rodauth/oauth/version" require "rodauth/oauth/ttl_store" require "rodauth/oauth/database_extensions" require "rodauth/oauth/refinements" module Rodauth @@ -685,12 +687,11 @@ else response["Cache-Control"] = "no-store" response["Pragma"] = "no-cache" end json_payload = _json_response_body(body) - response.write(json_payload) - request.halt + return_response(json_payload) end def throw_json_response_error(status, error_code, message = nil) set_response_error_status(status) code = if respond_to?(:"#{error_code}_error_code") @@ -701,20 +702,26 @@ payload = { "error" => code } payload["error_description"] = message || (send(:"#{error_code}_message") if respond_to?(:"#{error_code}_message")) json_payload = _json_response_body(payload) response["Content-Type"] ||= json_response_content_type response["WWW-Authenticate"] = oauth_token_type.upcase if status == 401 - response.write(json_payload) - request.halt + return_response(json_payload) end unless method_defined?(:_json_response_body) def _json_response_body(hash) if request.respond_to?(:convert_to_json) request.send(:convert_to_json, hash) else JSON.dump(hash) end + end + end + + if Gem::Version.new(Rodauth.version) < Gem::Version.new("2.23") + def return_response(body = nil) + response.write(body) if body + request.halt end end def authorization_required if accepts_json?