-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix unknown pkce method error when configured #1747
Changes from 1 commit
8cbe710
ccc9773
4d5be91
f042917
d244e69
7e2bf4b
a8ba995
45494da
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -6,6 +6,10 @@ class DoorkeeperError < StandardError | |||||||
def type | ||||||||
message | ||||||||
end | ||||||||
|
||||||||
def self.translate_options | ||||||||
{} | ||||||||
end | ||||||||
end | ||||||||
|
||||||||
class InvalidGrantReuse < DoorkeeperError | ||||||||
|
@@ -45,6 +49,14 @@ def self.name_for_response | |||||||
end | ||||||||
end | ||||||||
|
||||||||
class InvalidCodeChallengeMethod < BaseResponseError | ||||||||
def self.translate_options | ||||||||
{ | ||||||||
challenge_methods: Doorkeeper.config.pkce_code_challenge_methods_supported.join(", ") | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Re: pluralisation in https://github.com/doorkeeper-gem/doorkeeper/pull/1747/files#r1825345954
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, used this in ccc9773 |
||||||||
} | ||||||||
end | ||||||||
end | ||||||||
|
||||||||
UnableToGenerateToken = Class.new(DoorkeeperError) | ||||||||
TokenGeneratorNotFound = Class.new(DoorkeeperError) | ||||||||
NoOrmCleaner = Class.new(DoorkeeperError) | ||||||||
|
@@ -55,7 +67,6 @@ def self.name_for_response | |||||||
InvalidScope = Class.new(BaseResponseError) | ||||||||
InvalidRedirectUri = Class.new(BaseResponseError) | ||||||||
InvalidCodeChallenge = Class.new(BaseResponseError) | ||||||||
InvalidCodeChallengeMethod = Class.new(BaseResponseError) | ||||||||
InvalidGrant = Class.new(BaseResponseError) | ||||||||
|
||||||||
UnauthorizedClient = Class.new(BaseResponseError) | ||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ def self.from_request(request, attributes = {}) | |
attributes.merge( | ||
name: error_name_for(request.error), | ||
exception_class: exception_class_for(request.error), | ||
translate_options: request.error.try(:translate_options), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was not completely confident what classes There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe there's a default that can be set? grab :translate_options or fallback to {} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I default it here in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. More thinking of if the Error somehow doesn't derive from Doorkeeper::OAuth::Error, e.g., it comes from activerecord or something |
||
state: request.try(:state), | ||
redirect_uri: request.try(:redirect_uri), | ||
), | ||
|
@@ -33,7 +34,7 @@ def self.exception_class_for(error) | |
delegate :name, :description, :state, to: :@error | ||
|
||
def initialize(attributes = {}) | ||
@error = OAuth::Error.new(*attributes.values_at(:name, :state)) | ||
@error = OAuth::Error.new(*attributes.values_at(:name, :state, :translate_options)) | ||
@exception_class = attributes[:exception_class] | ||
@redirect_uri = attributes[:redirect_uri] | ||
@response_on_fragment = attributes[:response_on_fragment] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,10 +3,11 @@ | |
require "spec_helper" | ||
|
||
RSpec.describe Doorkeeper::OAuth::Error do | ||
subject(:error) { described_class.new(:some_error, :some_state) } | ||
subject(:error) { described_class.new(:some_error, :some_state, nil) } | ||
|
||
it { expect(error).to respond_to(:name) } | ||
it { expect(error).to respond_to(:state) } | ||
it { expect(error).to respond_to(:translate_options) } | ||
|
||
describe "#description" do | ||
it "is translated from translation messages" do | ||
|
@@ -17,5 +18,21 @@ | |
) | ||
error.description | ||
end | ||
|
||
context "when there are variables" do | ||
subject(:error) do | ||
described_class.new( | ||
:invalid_code_challenge_method, | ||
:some_state, | ||
{ | ||
challenge_methods: "foo, bar" | ||
} | ||
) | ||
end | ||
|
||
it "is translated from translation messages with variables" do | ||
expect(error.description).to eq("The code challenge method must be one of foo, bar.") | ||
end | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should have a test case for the "one" option, i.e., just "foo" not "foo, bar" (this likely more applies to pre_authorization_spec. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added a test for |
||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could probably use some tweaking, just let me know how you think this should read.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You'd probably want to use the one / other syntax here..
Which would need a
count
onchallenge_methods
, iirc.count
is magic in that it decides whether to pickone
orother
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome suggestions, I went ahead and updated in ccc9773