Skip to content

feat(auth): add configurable OAuth trust-provider-email account-linking policy - #13680

Open
ItsRoy69 wants to merge 16 commits into
appwrite:mainfrom
ItsRoy69:feat/oauth-trust-provider-email-policy
Open

ItsRoy69 wants to merge 16 commits into
appwrite:mainfrom
ItsRoy69:feat/oauth-trust-provider-email-policy

Conversation

@ItsRoy69

@ItsRoy69 ItsRoy69 commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Adds an opt-in project policy (PATCH /v1/project/policies/oauth-trust-provider-email) that lets self-hosted deployments trust the email reported by an OAuth provider when linking an OAuth sign-in to an existing account by email. The motivating case is Microsoft OAuth, where isEmailVerified() always returns false, so same-email linking never succeeds by default.

The policy stores a list of trusted provider IDs: auths.oauthTrustProviderEmailProviders (string[], default []). An empty list keeps the default strict behavior - an unverified email from any provider stays blocked. When a provider's ID is in the list, its reported (possibly unverified) email may link to an existing account with the same email.

Scope is intentionally limited to the email-link step in app/controllers/api/account.php. Other paths (canonicalization, verification emails, logged-in provider conflict, session token flow) are unchanged. Microsoft::isEmailVerified() still returns false, and the policy never sets Appwrite's emailVerification flag - that stays driven by the provider.

Trust only providers and directories you control (for example your own Microsoft tenant with accounts provisioned by IT). The policy affects email-based account linking only, not Appwrite-side email verification.

Test Plan

Ran locally:

  • tests/e2e/Services/Project - 909 tests / 6764 assertions (single failure is the password-dictionary CRLF artifact of this Windows checkout, unrelated to this PR)
  • tests/e2e/Services/Account - 106 tests / 1638 assertions, pass
  • Policy e2e (both console-client and server classes): enable / disable / idempotent / unauthenticated (401) / invalid type (400) / invalid provider (400) / missing providers (400)
  • OAuth e2e: policy off ? 400, trusting a different provider ? still 400, trusting mock-unverified ? 200 link, follow-up sign-in resolves the existing account, emailVerification stays false
  • php lint, Pint, and PHPStan (level 4) clean on the changed files

Related PRs and Issues

Checklist

  • Have you read the Contributing Guidelines on issues?
  • If the PR includes a change to an API's metadata (desc, label, params, etc.), does it also include updated API specs and example docs?

@ItsRoy69 ItsRoy69 changed the title feat(auth): add configurable OAuth trust-provider-email account-linki… feat(auth): add configurable OAuth trust-provider-email account-linking policy Sep 14, 2026
@greptile-apps

greptile-apps Bot commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

The PR appears safe to merge because no unresolved correctness, security, or repository-rule violation remains.

Summary

Adds an opt-in, provider-scoped OAuth account-linking policy that permits selected providers’ unverified email addresses to match existing accounts without marking those accounts’ emails as verified.

  • Adds the policy update, retrieval, listing, response-model, and project-default plumbing.
  • Applies the exception only when the current OAuth provider is explicitly listed.
  • Adds policy API coverage and end-to-end account-linking coverage, including cleanup and verification-state checks.

Reviews (14) · Last reviewed commit: "Merge branch 'main' into feat/oauth-trus..."

Comment thread app/controllers/api/account.php Resolved
…list

The oauth-trust-provider-email policy previously enabled email-based account linking for every OAuth provider at once. Gate linking per provider by storing an explicit list of trusted provider IDs; an empty list keeps the default behavior unchanged.

- PATCH /v1/project/policies/oauth-trust-provider-email now takes providers (array of provider IDs) instead of enabled
- Policy model exposes providers; the V26 response filter mirrors it as authOauthTrustProviderEmailProviders
- account.php only trusts a provider when it is in the stored list; a legacy boolean value on the project is normalized to an empty list
- Account e2e asserts the unverified email stays blocked for untrusted providers and that linking never marks the email verified; identity cleanup is scoped to identities of accounts owned by the test email
@greptile-apps

greptile-apps Bot commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

Want your agent to iterate on Greptile's feedback? Start a greploop in Claude Code and it will work through the open comments and keep going until this PR reviews clean.

This branch has not been deployed

No deployments
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