Skip to content

Commit

Permalink
Merge pull request #1755 from lurz/force_pkce_error_message
Browse files Browse the repository at this point in the history
Fix the error message for force_pkce
  • Loading branch information
nbulaj authored Dec 23, 2024
2 parents 0f0b6aa + b3d54e9 commit 6f249c8
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ User-visible changes worth mentioning.
## main

Add your entry here.
- [#1755] Fix the error message for force_pkce

## 5.8.1

Expand Down
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ en:
unknown: 'The request is missing a required parameter, includes an unsupported parameter value, or is otherwise malformed.'
missing_param: 'Missing required parameter: %{value}.'
request_not_authorized: 'Request need to be authorized. Required parameter for authorizing request is missing or invalid.'
invalid_code_challenge: 'Code challenge is required.'
invalid_redirect_uri: "The requested redirect uri is malformed or doesn't match client redirect URI."
unauthorized_client: 'The client is not authorized to perform this request using this method.'
access_denied: 'The resource owner or authorization server denied the request.'
Expand Down
1 change: 0 additions & 1 deletion lib/doorkeeper/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ def self.translate_options
InvalidClient = Class.new(BaseResponseError)
InvalidScope = Class.new(BaseResponseError)
InvalidRedirectUri = Class.new(BaseResponseError)
InvalidCodeChallenge = Class.new(BaseResponseError)
InvalidGrant = Class.new(BaseResponseError)

UnauthorizedClient = Class.new(BaseResponseError)
Expand Down
10 changes: 7 additions & 3 deletions lib/doorkeeper/oauth/pre_authorization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ class PreAuthorization
validate :response_type, error: Errors::UnsupportedResponseType
validate :response_mode, error: Errors::UnsupportedResponseMode
validate :scopes, error: Errors::InvalidScope
validate :code_challenge, error: Errors::InvalidCodeChallenge
validate :code_challenge, error: Errors::InvalidRequest
validate :code_challenge_method, error: Errors::InvalidCodeChallengeMethod

attr_reader :client, :code_challenge, :code_challenge_method, :missing_param,
:redirect_uri, :resource_owner, :response_type, :state,
:authorization_response_flow, :response_mode, :custom_access_token_attributes
:authorization_response_flow, :response_mode, :custom_access_token_attributes,
:invalid_request_reason

def initialize(server, parameters = {}, resource_owner = nil)
@server = server
Expand Down Expand Up @@ -147,7 +148,10 @@ def validate_scopes
def validate_code_challenge
return true unless Doorkeeper.config.force_pkce?
return true if client.confidential
code_challenge.present?
return true if code_challenge.present?

@invalid_request_reason = :invalid_code_challenge
false
end

def validate_code_challenge_method
Expand Down
1 change: 1 addition & 0 deletions spec/lib/oauth/pre_authorization_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@
attributes[:code_challenge] = " "

expect(pre_auth).not_to be_authorizable
expect(pre_auth.error_response.description).to eq(translated_invalid_request_error_message(:invalid_code_challenge, nil))
end

it "accepts a code challenge" do
Expand Down

0 comments on commit 6f249c8

Please sign in to comment.