Skip to content

Commit

Permalink
Use existing handle_auth_errors option instead of creating a new one
Browse files Browse the repository at this point in the history
  • Loading branch information
camero2734 committed Nov 8, 2023
1 parent 423dbe4 commit 41ae563
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 21 deletions.
2 changes: 1 addition & 1 deletion app/controllers/doorkeeper/authorizations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def render_success
def render_error
pre_auth.error_response.raise_exception! if Doorkeeper.config.raise_on_errors?

if Doorkeeper.configuration.redirect_on_error && pre_auth.error_response.redirectable?
if Doorkeeper.configuration.redirect_on_errors? && pre_auth.error_response.redirectable?
redirect_or_render(pre_auth.error_response)
elsif Doorkeeper.configuration.api_only
render json: pre_auth.error_response.body, status: pre_auth.error_response.status
Expand Down
13 changes: 4 additions & 9 deletions lib/doorkeeper/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,6 @@ def api_only
@config.instance_variable_set(:@api_only, true)
end

# Redirect on error instead of rendering error response
def redirect_on_error
@config.instance_variable_set(:@redirect_on_error, true)
end

# Enables polymorphic Resource Owner association for Access Grant and
# Access Token models. Requires additional database columns to be setup.
def use_polymorphic_resource_owner
Expand Down Expand Up @@ -459,10 +454,6 @@ def api_only
@api_only ||= false
end

def redirect_on_error
@redirect_on_error ||= false
end

def enforce_content_type
@enforce_content_type ||= false
end
Expand Down Expand Up @@ -510,6 +501,10 @@ def raise_on_errors?
handle_auth_errors == :raise
end

def redirect_on_errors?
handle_auth_errors == :redirect
end

def application_secret_hashed?
instance_variable_defined?(:"@application_secret_strategy")
end
Expand Down
12 changes: 4 additions & 8 deletions lib/generators/doorkeeper/templates/initializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -312,16 +312,12 @@
# Doorkeeper::Errors::TokenRevoked, Doorkeeper::Errors::TokenUnknown
#
# handle_auth_errors :raise

# If an exception occurs during the authorization request, Doorkeeper will, by
# default, render an HTML error response with the exception message and HTTP
# status code. If you want to redirect back to the client application in accordance
# with https://datatracker.ietf.org/doc/html/rfc6749#section-4.1.2.1, you can
# enable this option.
#
# This will have no effect if handle_auth_errors is set to :raise.
# If you want to redirect back to the client application in accordance with
# https://datatracker.ietf.org/doc/html/rfc6749#section-4.1.2.1, you can set
# +handle_auth_errors+ to :redirect
#
# redirect_on_error
# handle_auth_errors :redirect

# Customize token introspection response.
# Allows to add your own fields to default one that are required by the OAuth spec
Expand Down
5 changes: 2 additions & 3 deletions spec/controllers/authorizations_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1044,8 +1044,8 @@ def query_params
end
end

describe "GET #new with errors with redirect_on_error" do
before { config_is_set(:redirect_on_error, true) }
describe "GET #new with errors with handle_auth_errors :redirect" do
before { config_is_set(:handle_auth_errors, :redirect) }

context "without valid params" do
before do
Expand Down Expand Up @@ -1089,7 +1089,6 @@ def query_params
end

it "includes state in fragment" do
pry
expect(response.query_params["state"]).to eq("return-this")
end

Expand Down

0 comments on commit 41ae563

Please sign in to comment.