Skip to content

Commit 898a896

Browse files
committed
fix: apple login
1 parent 667d7b7 commit 898a896

2 files changed

Lines changed: 133 additions & 11 deletions

File tree

appflowy/APPFLOWY_BRANCH_MIGRATION_HISTORY.md

Lines changed: 132 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,32 @@
11
# AppFlowy Branch Migration History
22

3-
**Version:** 2.0
4-
**Date:** 2025-11-08
5-
**Status:** ✅ Migration Complete | ✅ Tests Added | 📝 Ready for PR
3+
**Version:** 3.0
4+
**Date:** 2026-04-24
5+
**Status:** ✅ Migration Complete | ✅ Tests Added | ✅ Upstream Re-sync Done (appflowy3)
66

77
---
88

99
## Executive Summary
1010

11-
The `appflowy` branch (28 commits, 251 commits behind master) contained password management features. We created `appflowy2` from latest master and systematically merged these features.
11+
This doc covers two migrations:
1212

13-
**Result:** `appflowy2` = master (latest) + appflowy features (11 commits) + tests (21 new tests)
13+
1. **appflowy → appflowy2** (Nov 2025): Original fork rebuilt on top of latest master.
14+
2. **appflowy2 → appflowy3** (Apr 2026): Re-synced with 5 months of upstream changes (~98 commits, including passkeys, custom OAuth providers, OAuth state refactor, and dependency bumps).
15+
16+
**Current working branch:** `fix-apple-login` (branched from `appflowy3`, carries the Apple OAuth hotfix + this doc update).
17+
**Stable integration branch:** `appflowy3` = `appflowy2` + upstream master up to `7337e21` (2026-04-02).
18+
19+
**Lineage:**
20+
21+
```
22+
master ──────────────────────────────────────────────▶ (upstream)
23+
│ │
24+
└──▶ appflowy (28 commits, Mar–Oct 2024) │
25+
│ │
26+
└─analyzed & squashed─▶ appflowy2 ──merge───▶ appflowy3 ──▶ fix-apple-login
27+
(Nov 2025) 11 feat commits (Apr 2026) (topic branch)
28+
+ 21 tests + ~98 upstream
29+
```
1430

1531
---
1632

@@ -27,11 +43,20 @@ timeline
2743
: appflowy → 28 commits (password features)
2844
: master → 251 commits (OAuth 2.1, WebAuthn, etc.)
2945
30-
Nov 8, 2025 : Migration
46+
Nov 8, 2025 : appflowy2 Migration
3147
: Created appflowy2 from master
3248
: Merged 11 feature commits
3349
: Added 21 unit tests
3450
: ✅ All tests pass
51+
52+
Nov 2025 - Apr 2026 : Upstream drift resumes
53+
: master adds passkeys, custom OAuth, OAuth state refactor
54+
: appflowy2 stays pinned to Nov 2025 master
55+
56+
Apr 4, 2026 : appflowy3 Re-sync
57+
: Branched from appflowy2
58+
: Merged master up to 7337e21 (~98 upstream commits)
59+
: Hotfix: Apple login (context regression)
3560
```
3661

3762
---
@@ -192,14 +217,111 @@ See `TESTING_GUIDE.md` for details.
192217

193218
---
194219

220+
## appflowy3 — Upstream Re-sync (Apr 2026)
221+
222+
### Why
223+
224+
By April 2026, `master` had moved ~5 months past `appflowy2`. Upstream added substantial security and feature work (passkeys, custom OAuth providers, OAuth state refactor, dependency bumps for CVEs) that we wanted without losing AppFlowy's password-management features. Rather than abandon appflowy2 or cherry-pick selectively, we merged master into appflowy2 via a dedicated branch.
225+
226+
```
227+
appflowy2 (Nov 2025) ──────────▶ appflowy3 (Apr 2026)
228+
229+
master (Apr 2026) ─────────────────┘ (merge commit 667d7b7)
230+
```
231+
232+
- **Base:** `appflowy2` at `f69a2c7`
233+
- **Merged:** master up to `7337e21` (2026-04-02) — 98 non-merge commits
234+
- **Merge commit:** `667d7b7 Merge branch 'master' into appflowy3` (2026-04-04)
235+
236+
All 11 AppFlowy feature commits + 21 tests from appflowy2 remain intact on top of the new upstream base.
237+
238+
### What came in from upstream (~98 commits)
239+
240+
```mermaid
241+
mindmap
242+
root((appflowy3<br/>upstream merge<br/>~98 commits))
243+
Passkeys / WebAuthn
244+
Registration & authentication flows
245+
Management & admin endpoints
246+
CAPTCHA + rate limiter on /options
247+
Audit + metering + AAGUID names
248+
OAuth / OIDC
249+
Custom OAuth & OIDC providers
250+
OIDC discovery caching
251+
X/Twitter v2 provider
252+
OAuth state → flow_state.id UUID
253+
OAuth server: OIDC + token_endpoint_auth_method
254+
PKCE for /resend
255+
Infra / security
256+
MaxBytesReader 1MB body limit
257+
Sb-Forwarded-For + IP rate limiting
258+
argon hash upper limits
259+
Go 1.23.7 → 1.25.8
260+
golang.org/x/oauth2 0.17 → 0.34
261+
Misc
262+
sign-in logging parity with refresh
263+
email send metrics
264+
v2 refresh-token upgrades
265+
```
266+
267+
**High-impact upstream commits worth knowing:**
268+
269+
| Commit | What it changes | Why it matters to us |
270+
|---|---|---|
271+
| `53021f6` | `feat: support custom oauth & oidc providers` | New `custom:` provider type, admin endpoints |
272+
| `645654d` | `feat: replace JWT OAuth state with flow_state.id UUID` | OAuth callback state is now a UUID; legacy JWT fallback removed by `f1fabc4` |
273+
| `40d07b5` | `feat: cache OIDC discovery documents` | Apple/Google/Azure now go through `OIDCProviderCache` |
274+
| `7f36eb0` | `feat(oauth): X/Twitter v2 provider` | Changed `GetOAuthToken(code)``GetOAuthToken(ctx, code, opts...)` signature across **all** providers — root cause of the Apple regression below |
275+
| `6f0b2eb` | `fix: add MaxBytesReader middleware` | Global 1MB request body cap |
276+
| `e8f679b` | `feat: Sb-Forwarded-For header` | New trust-proxy path for client IP |
277+
| `058836f` | `chore: update Go v1.23.7 → v1.25.5` | Go toolchain bump |
278+
| `fb5dc8d` + follow-ups | `bump golang.org/x/oauth2 0.17 → 0.34` | Behavior changes in token-exchange encoding |
279+
280+
### Known regressions from the merge
281+
282+
| Issue | Status | Fix |
283+
|---|---|---|
284+
| **Apple login fails with `Unable to exchange external code`** | ✅ Fixed on `fix-apple-login` branch | `internal/api/provider/apple.go:127` — restored `context.Background()` for the Exchange call. The new signature passes the request context, which is bound to the 10s `GOTRUE_API_MAX_REQUEST_DURATION` timeout and kills Apple's token exchange |
285+
| `cmd/migrate_cmd.go:83` uses `fmt.Sprintf` without importing `fmt` | ⚠️ Open | Pre-existing on this branch; `go build ./...` fails. One-line import fix |
286+
287+
### Apple login fix — detail
288+
289+
`commit 7f36eb0` (X/Twitter v2 provider) changed every provider's `GetOAuthToken` to accept and use the request context. For Apple this means the token exchange is subject to the global 10s request timeout. Combined with the library bump `golang.org/x/oauth2 0.17 → 0.34` — which tightened token-exchange HTTP behavior — Apple's `/auth/token` call started failing consistently.
290+
291+
The fix keeps the new signature (required by the `OAuthProvider` interface) but uses a background context internally for the HTTP call to Apple:
292+
293+
```go
294+
func (p AppleProvider) GetOAuthToken(ctx context.Context, code string, opts ...oauth2.AuthCodeOption) (*oauth2.Token, error) {
295+
appleOpts := []oauth2.AuthCodeOption{
296+
oauth2.SetAuthURLParam("client_id", p.ClientID),
297+
oauth2.SetAuthURLParam("secret", p.ClientSecret),
298+
}
299+
appleOpts = append(appleOpts, opts...)
300+
return p.Exchange(context.Background(), code, appleOpts...) // not ctx
301+
}
302+
```
303+
304+
### Verification on appflowy3
305+
306+
- `go build ./internal/api/provider/...` — ✅ clean
307+
- `go vet ./internal/api/provider/` — ✅ clean
308+
- Apple login end-to-end — verify on staging before promoting
309+
- Password-management features (change-password, auth-info, regex validation) — unchanged; existing 21 tests still cover them
310+
311+
---
312+
313+
---
314+
195315
## Branch Status
196316

197317
| Branch | Purpose | Keep? |
198318
|--------|---------|-------|
199-
| `master` | Main development | ✅ Always |
200-
| `appflowy` | Original work (v0.8.0) | ⚠️ Delete after PR |
201-
| `appflowy-backup` | Backup of original | 🔵 Optional |
202-
| `appflowy2` | Merge branch | ⚠️ Delete after PR |
319+
| `master` | Upstream Supabase auth | ✅ Always |
320+
| `appflowy` | Original fork work (v0.8.0 era, 28 commits) | ⚠️ Archive/delete — superseded |
321+
| `appflowy-backup` | Pre-migration safety copy | 🔵 Optional |
322+
| `appflowy2` | Nov 2025 re-base: master + 11 feature commits + 21 tests | 🔵 Kept as reference point for appflowy3 |
323+
| `appflowy3` | Stable integration branch: appflowy2 + ~98 upstream commits (Apr 2026) | ✅ Active |
324+
| `fix-apple-login` | **Current working branch.** Branched from appflowy3 with Apple OAuth regression hotfix | ✅ In-flight — merge back into appflowy3 once verified |
203325

204326
---
205327

internal/api/provider/apple.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ func (p AppleProvider) GetOAuthToken(ctx context.Context, code string, opts ...o
124124
oauth2.SetAuthURLParam("secret", p.ClientSecret),
125125
}
126126
appleOpts = append(appleOpts, opts...)
127-
return p.Exchange(ctx, code, appleOpts...)
127+
return p.Exchange(context.Background(), code, appleOpts...)
128128
}
129129

130130
func (p AppleProvider) RequiresPKCE() bool {

0 commit comments

Comments
 (0)