Skip to content

Add Resend OAuth2 adapter - #13366

Merged
Meldiron merged 7 commits into
mainfrom
feat-resend-oauth2
Aug 27, 2026
Merged

Meldiron merged 7 commits into
mainfrom
feat-resend-oauth2

Conversation

@Meldiron

@Meldiron Meldiron commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

To create client:

curl -X POST 'https://api.resend.com/oauth/register' \
     -H 'Content-Type: application/json' \
     -d '{
  "client_name": "Appwrite QA Matej manual",
  "redirect_uris": [
    "http://localhost/v1/account/sessions/oauth2/callback/resend/myprojectid"
  ],
  "grant_types": ["authorization_code", "refresh_token"],
  "response_types": ["code"],
  "token_endpoint_auth_method": "client_secret_post",
  "scope": "emails:send",
  "client_secret_expires_at": 0
}'
CleanShot 2026-08-27 at 15 08 33@2x CleanShot 2026-08-27 at 15 08 41@2x CleanShot 2026-08-27 at 15 08 31@2x CleanShot 2026-08-27 at 15 08 50@2x CleanShot 2026-08-27 at 15 08 46@2x

What does this PR do?

Adds Resend as an OAuth2 social sign-in provider. Related to #13347 (Resend part).

Resend runs a standard OAuth 2.1 authorization server at api.resend.com/oauth (client guide, server metadata). Three provider quirks shaped the adapter:

  • PKCE (S256) is mandatory, so the adapter uses the existing PKCE trait exactly like Kick — verifier encrypted into the state, restored in parseState().
  • No userinfo endpoint and no id_token. Identity lives only in the RFC 9068 JWT access token, so getUserID() decodes the JWT payload (base64url) and reads sub. The token arrives over TLS directly from the token endpoint and is never used to authorize anything on our side, so the signature is not verified. Email and name are not exposed, so getUserEmail()/getUserName() return empty and isEmailVerified() is false — supported since email became optional in feat(account): make email optional for OAuth2 account linking #13255.
  • Scopes are only full_access and emails:send, and omitting scope grants both, so the adapter pins emails:send as the least-privilege default.

The adapter is a confidential client: client_secret_post authentication (client_id + client_secret in the token request body) plus PKCE.

verifyCredentials() follows the HuggingFace pattern (#13123) with one deliberate deviation, validated live against the endpoint: Resend validates request shape before authenticating the client, so a non-URL redirect_uri returns invalid_request even for bogus credentials and would mask them. With a well-formed URL, bogus credentials correctly return invalid_client, so the probe uses a URL-shaped invalid redirect (commented in code).

Changes

  • src/Appwrite/Auth/OAuth2/Resend.php — the adapter
  • app/config/oAuthProviders.php — resend provider entry
  • Project/Http/Project/OAuth2/Resend/Update.php + Project/Services/Http.php — console updateOAuth2Resend endpoint
  • Response.php (MODEL_OAUTH2_RESEND), Response/Model/OAuth2Resend.php, app/init/models.php — response model
  • tests/unit/Auth/OAuth2/PKCETest.php — Resend added to the PKCE provider matrix

Notes

  • The console app needs an icon-resend asset (same follow-up as when Kick landed).
  • Accounts created via Resend have an empty email until the user sets one, since Resend exposes no email through OAuth.

Test Plan

  • Unit: full tests/unit/ suite passes (1079 tests, 16113 assertions); tests/unit/Auth/OAuth2/ fully clean at 47/47 including 8 new resend PKCE data sets.
  • Live-probed https://api.resend.com/oauth/token to confirm the verifyCredentials() error contract (invalid_client for unknown credentials, invalid_request when the redirect is not a URL).
  • Smoke-tested login URL generation in-container: correct authorize URL, S256 challenge, encrypted verifier in state.
  • Pint and PHPStan (level 4) clean on all touched files.

Related PRs and Issues

🤖 Generated with Claude Code

Meldiron and others added 4 commits August 26, 2026 17:08
Co-Authored-By: Claude Fable 5 <[email protected]>
Basic auth already identifies the client, so client_id is not
repeated in the token, refresh, and credential-check bodies, per
the Resend OAuth client guide.

Co-Authored-By: Claude Fable 5 <[email protected]>
Adding the update action to the service only wires up the route.
The console provider list filters on getProviderActions(), and the
provider read endpoints declare a union of response models, so
Resend needs an entry in all three to be visible and documented.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Identity comes from the JWT access token rather than a userinfo
call, so the claim decoding is the adapter's own logic and carries
its own failure modes: base64url segments, unpadded input, and
callback-reachable tokens that must not raise.

Also pins the documented token request shape, which sends the
client id via Basic auth only.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@github-actions

github-actions Bot commented Aug 26, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → feat-resend-oauth2 (after).

Metric Before After Change
🚀 Requests/sec 212 210.97 ⚪ -0.5%
⏱️ Latency P50 84.78 ms 84.66 ms ⚪ -0.1%
⏱️ Latency P95 180.97 ms 182.31 ms ⚪ +0.7%
Per-scenario breakdown & investigation details

Metrics below reflect the current branch (after). Δ P95 compares against the base.

Scenario P50 (ms) P95 (ms) Requests RPS Δ P95 (ms)
API total 84.66 182.31 13,338 210.97 +1.34
Account 143 284.93 702 11.64 +12.6
TablesDB 87.52 159.58 7,254 116.94 +5.69
Storage 67.63 153.48 3,510 58.89 -0.67
Functions 104.91 210.12 1,872 32.14 +2.32

Top API waits (after)

API request Max wait (ms)
tablesdb.rows.create 489.19
account.get 472.09
storage.buckets.create 427.47
functions.create 409.95
functions.delete 398.37

Send client_id and client_secret in the request body instead of a Basic
authorization header, matching clients registered with the
client_secret_post token endpoint auth method.

Co-Authored-By: Claude Fable 5 <[email protected]>
@Meldiron
Meldiron marked this pull request as ready for review August 27, 2026 15:59

@Meldiron Meldiron left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

lgtm

@greptile-apps

greptile-apps Bot commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

Adds Resend as an OAuth2 provider with mandatory PKCE, JWT access-token identity extraction, credential validation, project configuration endpoints, and response-model registration.

  • Registers Resend in the OAuth provider and project-action registries.
  • Adds its OAuth adapter, project update action, and response model.
  • Extends shared PKCE tests to cover the new provider.

Confidence Score: 5/5

The PR appears safe to merge based on the available follow-up review evidence.

No blocking failure remains.

Important Files Changed

Filename Overview
src/Appwrite/Auth/OAuth2/Resend.php Implements Resend authorization, token exchange and refresh, PKCE state restoration, JWT subject extraction, and credential validation; no eligible follow-up finding was established.
src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Resend/Update.php Defines the Resend project configuration action and connects it to the shared OAuth2 persistence behavior.
src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Base.php Adds Resend to the provider-action registry used by project OAuth configuration reads.
src/Appwrite/Platform/Modules/Project/Services/Http.php Registers the Resend OAuth2 update action with the project HTTP service.
src/Appwrite/Utopia/Response/Model/OAuth2Resend.php Adds the Resend-specific project OAuth2 response model.
app/init/models.php Registers the Resend response model during application initialization.
tests/unit/Auth/OAuth2/PKCETest.php Adds Resend to the shared PKCE verifier, challenge, state, and callback test matrix.

Reviews (3): Last reviewed commit: "Bump utopia-php/migration to 2.0.5" | Re-trigger Greptile

Picks up the 'resend' entry in the OAuth2 provider migration
allow-list (utopia-php/migration#223), fixing the Migrations
E2E failure "No migration resource for OAuth2 provider 'resend'".

Co-Authored-By: Claude Fable 5 <[email protected]>
@Meldiron
Meldiron merged commit d828bde into main Aug 27, 2026
124 of 126 checks passed
imtia33 pushed a commit to imtia33/appwrite that referenced this pull request Oct 15, 2026
Appwrite server is adding a built-in 'resend' OAuth2 provider
(appwrite#13366). Without an entry in the PROVIDERS
allow-list, migrations report "No migration resource for OAuth2
provider 'resend'; skipped." and the transfer fails.

Only clientId migrates (to the resendAppid attribute); clientSecret
is write-only and stays redacted per the existing policy.

Co-Authored-By: Claude Fable 5 <[email protected]>
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