Skip to content

feat(auth): add Cloudflare Dashboard OAuth2 provider - #13391

Merged
Meldiron merged 5 commits into
appwrite:mainfrom
imtia33:feat/Cloudflare-Oauth2-Provider
Aug 27, 2026
Merged

Meldiron merged 5 commits into
appwrite:mainfrom
imtia33:feat/Cloudflare-Oauth2-Provider

Conversation

@imtia33

@imtia33 imtia33 commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Adds Cloudflare as an OAuth2 login provider via Cloudflare Dashboard OAuth2 — the consumer "Login with Cloudflare" flow at dash.cloudflare.com. Any Cloudflare user can consent to give an Appwrite app access to their Cloudflare account. Use cases include third-party apps that manage DNS, Workers, or other Cloudflare API resources on behalf of the user.

This is NOT Cloudflare Zero Trust. Zero Trust is per-tenant corporate SaaS OIDC; Dashboard OAuth2 is global consumer OIDC (Great naming by cloudflare, now I really wont trust anyone , specially if its their name or their service name).

Endpoints

All global:

  • Authorize: https://dash.cloudflare.com/oauth2/auth
  • Token: https://dash.cloudflare.com/oauth2/token
  • UserInfo: https://dash.cloudflare.com/oauth2/userinfo
  • Discovery: https://dash.cloudflare.com/.well-known/openid-configuration (returns 200 with RFC 8414 metadata)

Identity

Cloudflare's OIDC discovery doc advertises claims_supported: ["sub"] — only the sub claim is exposed via userinfo. No email, name, or picture. Cloudflare users in Appwrite will have empty email and empty name. Account deduplication is via (provider='cloudflare', providerUid=<sub>). Supported by Appwrite thanks to PR #13255 (email optional for OAuth2 account linking).

PKCE

Uses Appwrite's PKCE trait with S256 challenge method — consistent with Etsy, Kick, X, and Appwrite providers. verifyCredentials() uses client_secret_post only (no Basic auth header).

Setup

Admins register an OAuth client at https://dash.cloudflare.com → Manage Account → OAuth clients → Create client. Select authorization_code grant, client_secret_post auth method, redirect URI https://<appwrite-host>/v1/account/oauth2/callback/cloudflare, and at least the openid scope. To allow any Cloudflare user (not just parent-account members) to authorize, promote the client to public visibility — requires client name, logo, client URL, scopes, AND client URL domain ownership verification (DNS TXT). Public promotion is permanent.

Reference: https://developers.cloudflare.com/fundamentals/oauth/

Test Plan

  • Manual QA: real Cloudflare Dashboard OAuth2 client (public visibility, openid scope), full OAuth2 callback flow, decode the resulting JWT to confirm sub is present

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? (SDK spec update will follow in a separate step once composer spec is run in CI)

@greptile-apps

greptile-apps Bot commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

Adds Cloudflare Dashboard OAuth2 as a configurable authentication provider.

  • Implements authorization-code exchange, PKCE, token refresh, Cloudflare user retrieval, and credential verification.
  • Registers the provider’s project endpoint, configuration, response models, and service action.
  • Adds provider-list and PKCE test coverage and updates the migration dependency lock.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
src/Appwrite/Auth/OAuth2/Cloudflare.php Implements the Cloudflare OAuth2 authorization, token, refresh, identity, PKCE, and credential-verification behavior.
src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Cloudflare/Update.php Defines the Cloudflare project configuration endpoint metadata and response model.
src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Base.php Adds Cloudflare to the provider-action lookup used by the shared OAuth2 project routes.
src/Appwrite/Platform/Modules/Project/Services/Http.php Registers the Cloudflare OAuth2 update action with the project HTTP service.
src/Appwrite/Utopia/Response/Model/OAuth2Cloudflare.php Adds the provider-specific response model with identifiers consistent with the configuration and route.
app/init/models.php Registers the Cloudflare response model during application initialization.
tests/unit/Auth/OAuth2/PKCETest.php Extends shared PKCE behavior coverage to the Cloudflare provider.
composer.lock Updates utopia-php/migration from 2.0.5 to 2.0.6.

Reviews (4): Last reviewed commit: "Use Cloudflare API user details for iden..." | Re-trigger Greptile

Meldiron and others added 2 commits August 27, 2026 22:19
Cloudflare OAuth clients cannot be granted the 'openid' scope - the
dashboard scope picker and the /oauth/scopes API only offer Cloudflare
API permission scopes. Request 'user-details.read' and 'offline_access'
instead, and read identity (id, email, name) from the Cloudflare API
user details endpoint, which also improves on userinfo's bare 'sub'.

Co-Authored-By: Claude Fable 5 <[email protected]>
@Meldiron

Copy link
Copy Markdown
Contributor

Manual QA

CleanShot 2026-08-27 at 22 14 54@2x CleanShot 2026-08-27 at 22 28 46@2x CleanShot 2026-08-27 at 22 28 49@2x CleanShot 2026-08-27 at 22 29 02@2x CleanShot 2026-08-27 at 22 29 11@2x CleanShot 2026-08-27 at 22 33 17@2x

@Meldiron

Copy link
Copy Markdown
Contributor

Improved version, also sees email

CleanShot 2026-08-27 at 22 37 06@2x CleanShot 2026-08-27 at 22 37 11@2x

@Meldiron

Copy link
Copy Markdown
Contributor

Heads up on two pushed changes after real end-to-end QA against a live Cloudflare OAuth client (the test plan's manual QA was still unchecked):

1. Identity now comes from the Cloudflare API, not OIDC userinfo (877a3ec)

The openid scope cannot be granted to Cloudflare OAuth clients — the dashboard scope picker and GET /client/v4/oauth/scopes (383 entries) only offer Cloudflare API permission scopes, and the authorize endpoint rejects scope=openid with invalid_scope for every client. So the userinfo-based design could never complete a live flow.

The adapter now requests user-details.read + offline_access and reads identity from GET https://api.cloudflare.com/client/v4/user. Side benefit: Appwrite now gets a real email and name (id, email, first_name/last_name) instead of userinfo's bare sub, so accounts are no longer created with empty email.

2. Setup instructions in the description need updating

  • Redirect URI format is https://<host>/v1/account/sessions/oauth2/callback/cloudflare/<PROJECT_ID> (the description's /v1/account/oauth2/callback/cloudflare is missing the /sessions segment and project ID).
  • Scopes: select User Details Read (under Account & Billing) when creating the client — not openid, which isn't offered. Enable the Refresh Token grant so offline_access is registered; the adapter requests it for token refresh.

Verified: authorize URL accepted by Cloudflare (redirects to login with a challenge), credential verification passes, PKCE unit tests green.

🤖 Generated with Claude Code

@Meldiron
Meldiron merged commit a656e87 into appwrite:main Aug 27, 2026
45 checks passed
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.

2 participants