Skip to content

fix(abstractions): preserve multi-valued query parameters in ApiKeyAuthenticationProvider - #913

Closed
Hardik K (hardikkaurani) wants to merge 2 commits into
microsoft:mainfrom
hardikkaurani:fix/api-key-preserve-multi-value-query-parameters
Closed

Hardik K (hardikkaurani) wants to merge 2 commits into
microsoft:mainfrom
hardikkaurani:fix/api-key-preserve-multi-value-query-parameters

Conversation

@hardikkaurani

Copy link
Copy Markdown
Contributor

Summary

When ApiKeyAuthenticationProvider authenticates a request using KeyLocation.QueryParameter, it parsed the query component of request.url via dict(parse_qsl(url_parts[4], keep_blank_values=True)).

Converting parse_qsl directly to a Python dict causes all repeated / multi-valued query parameters (such as ?id=1&id=2 or ?expand=orders&expand=items) to be collapsed into a single key-value pair, silently discarding earlier values.

This PR preserves all existing query parameters as a list of key-value pairs (parse_qsl), filters out any existing parameter matching self.parameter_name (to avoid duplicate key insertions if updating or re-authenticating), appends (self.parameter_name, self.api_key), and re-encodes the query string via urlencode.

Changes

  • Commit 1 (fix): Update ApiKeyAuthenticationProvider.authenticate_request to preserve multi-valued query parameter pairs instead of collapsing them into a dictionary.
  • Commit 2 (test): Add regression tests verifying that:
    • Multi-valued query parameters (?id=1&id=2&select=name) are preserved alongside the newly added API key.
    • An existing API key parameter is updated without dropping or mutating preceding repeated query parameters.

Verification

Ran test suites and linters locally against packages/abstractions:

  • pytest: 268/268 passed (100% pass rate)
  • mypy kiota_abstractions: Success (no issues found in 48 source files)
  • pylint kiota_abstractions --disable=W --rcfile=.pylintrc: 10.00/10
  • yapf -dr kiota_abstractions: clean
  • isort --check kiota_abstractions/authentication/api_key_authentication_provider.py: clean
  • pytest packages/http/httpx: 227/227 passed

…thenticationProvider

Signed-off-by: Hardik Kaurani <hardikkaurani1@gmail.com>
…eters in ApiKeyAuthenticationProvider

Signed-off-by: Hardik Kaurani <hardikkaurani1@gmail.com>
@hardikkaurani
Hardik K (hardikkaurani) requested a review from a team as a code owner November 20, 2026 16:55
Copilot AI balanced review requested due to automatic review settings November 20, 2026 16:55

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@hardikkaurani

Copy link
Copy Markdown
Contributor Author

Hi Vincent Biret (@baywet),

This PR addresses an issue where multi-valued query parameters were lost when authenticating requests with ApiKeyAuthenticationProvider using KeyLocation.QueryParameter:

  • Previously, dict(parse_qsl(url_parts[4], keep_blank_values=True)) converted parsed query parameters into a dictionary, which silently dropped duplicate keys (e.g. repeated filters or identifiers such as ?id=1&id=2) in favor of only the last pair.
  • The query string handling now preserves the sequence of key-value pairs from parse_qsl, replaces any existing matching parameter key, and appends the new key pair before re-encoding with urlencode.
  • Added unit tests covering repeated query parameters and existing key rotation.

All checks pass locally in packages/abstractions (268/268 tests, mypy, yapf, isort, and pylint 10.00/10). Please let me know if you would like any adjustments.

@baywet

Copy link
Copy Markdown
Member

Hi Hardik K (@hardikkaurani), thank you for your contribution!

This pull request is being closed automatically because you currently have more than 10 open pull requests across the Kiota repositories. Reviewing takes time, and having this many pull requests open at once overwhelms the reviewers. Please avoid having more than 10 open pull requests at any given time.

The following pull requests remain open:

To move forward, you can either:

  • Wait for your existing pull requests to get merged, and make sure to respond timely to any feedback to help move things along.
  • Close older pull requests that are no longer relevant, and then re-open this one.

@github-project-automation github-project-automation Bot moved this to Done ✔️ in Kiota Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done ✔️

Development

Successfully merging this pull request may close these issues.

3 participants