Skip to content

fix: keep optional credentials in location and OAuth URLs - #1911

Open
HarshMN2345 wants to merge 1 commit into
mainfrom
fix/location-optional-auth
Open

HarshMN2345 wants to merge 1 commit into
mainfrom
fix/location-optional-auth

Conversation

@HarshMN2345

Copy link
Copy Markdown
Member

What does this PR do?

Since #1891, securitySchemes skips schemes that security only accepts as an alternative. That is right for examples, but the web, React Native, Dart, Flutter, Swift, Android and .NET templates also use this filter to put client credentials into location and OAuth URLs. The Appwrite spec now lists ImpersonateUserId only in the second security alternative for location methods, so regenerated SDKs stopped adding impersonateuserid to those URLs. A console user who is impersonating someone and downloads a deployment, previews a file or loads an avatar sends the request as themselves and gets a 401.

This PR adds a urlSecuritySchemes filter that keeps optional schemes and uses it in the templates that build these URLs. Examples still skip them.

Test Plan

  • Generated web console from the published open-api3-latest.json before and after the change. The only difference is 16 restored payload['impersonateuserid'] = this.client.config.impersonateuserid; lines in avatars, functions, organizations, sites and storage. This matches the console SDK built before feat: derive optional security from OpenAPI alternatives #1891. Docs examples are unchanged.
  • react-native client gets back the same line in avatars and storage. flutter, android and apple client output is unchanged.
  • format:check, lint and analyse pass for the generated web and React Native SDKs.
  • tests/generation/GenerationTest.php passes, including testExamplesRespectSecurityAlternatives. phpcs, rector and djlint pass on the changed files.
  • Against a local Appwrite, the deployment download URL with impersonateuserid returns 200 for an impersonator. Without it the same request returns 401.

Location and OAuth methods build their URL from the same schemes as
examples. Examples now skip schemes that security marks optional, so
impersonation was also dropped from download, preview and avatar URLs
and the request ran as the caller instead of the impersonated user.

Add a urlSecuritySchemes filter that keeps optional schemes and use it
wherever a template embeds credentials into a URL. Examples still skip
them.
@greptile-apps

greptile-apps Bot commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

This PR is not yet safe to merge because the intended .NET fix is a no-op and leaves optional credentials absent from generated location and OAuth URLs.

Fix All in Claude CodeFindings

  1. P1 **.NET URLs Remain Unfixed**
  2. P2 **URL Behavior Lacks Coverage**
Fix with agent prompt
### Issue 1
templates/dotnet/base/utils.twig:12
The .NET change updates only `methodNeedsSecurityParameters`, but that macro has no callers. The code that actually builds parameters for location and OAuth requests still does not use `urlSecuritySchemes`. Generated .NET URLs therefore continue to omit optional credentials such as `impersonateuserid`, so impersonated requests can run as the caller and fail authorization. The new filter must be used by the parameter-building path consumed by `location.twig` and `oauth.twig`.

### Issue 2
src/SDK/SDK.php:188
This new filter and its template integrations change generated URL behavior without an observable regression test. The existing security-alternative test protects example generation, but it does not verify that location and OAuth output includes optional credentials while examples exclude them. That gap allowed the ineffective .NET integration to go unnoticed. Please add a generation test that renders representative optional security alternatives and checks the generated URL behavior across the affected template families.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

This PR separates URL credential generation from example credential generation so optional security alternatives can be retained for location and OAuth URLs.

  • Adds the urlSecuritySchemes Twig filter, which retains optional accepted schemes.
  • Adopts the filter in web, React Native, Dart, Flutter, Swift, Android, and nominally .NET templates.
  • The .NET adoption is ineffective because the changed macro is unused and its URL parameter construction remains unchanged.
  • The behavior is not covered by a focused generated-output regression test.

Reviews (1) · Last reviewed commit: "fix: keep optional credentials in locati..."

{% endmacro %}
{% macro methodNeedsSecurityParameters(method) %}
{% if ((method | methodType) == "webAuth" or (method | methodType) == "location") and [(method | securitySchemes)]|length > 0 %}{{ true }}{% else %}{{false}}{% endif %}
{% if ((method | methodType) == "webAuth" or (method | methodType) == "location") and [(method | urlSecuritySchemes)]|length > 0 %}{{ true }}{% else %}{{false}}{% endif %}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 The .NET change updates only methodNeedsSecurityParameters, but that macro has no callers. The code that actually builds parameters for location and OAuth requests still does not use urlSecuritySchemes. Generated .NET URLs therefore continue to omit optional credentials such as impersonateuserid, so impersonated requests can run as the caller and fail authorization. The new filter must be used by the parameter-building path consumed by location.twig and oauth.twig.

Prompt To Fix With AI
This is a comment left during a code review.
Path: templates/dotnet/base/utils.twig
Line: 12

Comment:
The .NET change updates only `methodNeedsSecurityParameters`, but that macro has no callers. The code that actually builds parameters for location and OAuth requests still does not use `urlSecuritySchemes`. Generated .NET URLs therefore continue to omit optional credentials such as `impersonateuserid`, so impersonated requests can run as the caller and fail authorization. The new filter must be used by the parameter-building path consumed by `location.twig` and `oauth.twig`.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Fix in Claude Code Fix in Codex

Comment thread src/SDK/SDK.php
$this->twig->addFilter(new TwigFilter('methodHeaders', fn(Operation $operation): array => $this->getMethodHeaders($operation)));
$this->twig->addFilter(new TwigFilter('responseDiscriminator', fn(Operation $operation): array => $this->getResponseDiscriminator($operation)));
$this->twig->addFilter(new TwigFilter('securitySchemes', fn(Operation $operation): array => $this->getOperationAuthSchemes($operation)));
$this->twig->addFilter(new TwigFilter('urlSecuritySchemes', fn(Operation $operation): array => $this->getOperationAuthSchemes($operation, optional: true)));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 This new filter and its template integrations change generated URL behavior without an observable regression test. The existing security-alternative test protects example generation, but it does not verify that location and OAuth output includes optional credentials while examples exclude them. That gap allowed the ineffective .NET integration to go unnoticed. Please add a generation test that renders representative optional security alternatives and checks the generated URL behavior across the affected template families.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/SDK/SDK.php
Line: 188

Comment:
This new filter and its template integrations change generated URL behavior without an observable regression test. The existing security-alternative test protects example generation, but it does not verify that location and OAuth output includes optional credentials while examples exclude them. That gap allowed the ineffective .NET integration to go unnoticed. Please add a generation test that renders representative optional security alternatives and checks the generated URL behavior across the affected template families.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Fix in Claude Code Fix in Codex

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant