# OAuth Connection Flow

```
┌─────────────────────────────────────────────────────────────────────────────┐
│                    INLINE FEEDBACK — OAUTH CONNECTION FLOW                   │
└─────────────────────────────────────────────────────────────────────────────┘

 WP Admin                  WordPress Plugin              Inline Feedback API
 (Browser)                 (Connect Handler)             (app.inline-feedback.com)
    │                            │                              │
    │  1. Click "Connect"        │                              │
    │  ───────────────────────>  │                              │
    │  POST admin-post.php       │                              │
    │  ?action=inlf_connect      │                              │
    │                            │                              │
    │                      ┌─────┴──────┐                       │
    │                      │ Verify:    │                       │
    │                      │ • nonce    │                       │
    │                      │ • cap      │                       │
    │                      │ • origin   │                       │
    │                      └─────┬──────┘                       │
    │                            │                              │
    │                      ┌─────┴──────────┐                   │
    │                      │ Generate state │                   │
    │                      │ Store in       │                   │
    │                      │ transient      │                   │
    │                      │ (10 min TTL)   │                   │
    │                      └─────┬──────────┘                   │
    │                            │                              │
    │  2. Redirect (302)         │                              │
    │  <─────────────────────────│                              │
    │                            │                              │
    │  3. GET /integrations/wordpress/authorize                 │
    │     ?callback_url=...&site_url=...&state=...              │
    │  ─────────────────────────────────────────────────────>   │
    │                                                           │
    │                                                     ┌─────┴──────┐
    │                                                     │ User logs  │
    │                                                     │ in and     │
    │                                                     │ authorizes │
    │                                                     │ connection │
    │                                                     └─────┬──────┘
    │                                                           │
    │  4. Redirect back to callback_url                         │
    │     ?page=inline-feedback&code=...&state=...              │
    │  <────────────────────────────────────────────────────────│
    │                            │                              │
    │  5. Load settings page     │                              │
    │  ───────────────────────>  │                              │
    │                            │                              │
    │                      ┌─────┴──────────┐                   │
    │                      │ Validate state │                   │
    │                      │ vs transient   │                   │
    │                      │ (hash_equals)  │                   │
    │                      └─────┬──────────┘                   │
    │                            │                              │
    │                    ┌───────┴───────┐                      │
    │                    ▼               ▼                      │
    │              ┌──────────┐   ┌───────────┐                │
    │              │ Mismatch │   │   Match   │                │
    │              └────┬─────┘   └─────┬─────┘                │
    │                   │               │                      │
    │                   ▼               │                      │
    │           ┌───────────────┐       │                      │
    │           │ Redirect with │       │                      │
    │           │ ?connect-error│       │                      │
    │           │ =invalid-state│       │                      │
    │           └───────────────┘       │                      │
    │                                   │                      │
    │                             6. Exchange code for token    │
    │                                   │  POST /exchange      │
    │                                   │  {code, site_url}    │
    │                                   ├─────────────────────>│
    │                                   │                      │
    │                                   │  Response:           │
    │                                   │  {connection_id,     │
    │                                   │   token,             │
    │                                   │   widget_key,        │
    │                                   │   workspace_name,    │
    │                                   │   widget_config}     │
    │                                   │<─────────────────────│
    │                                   │                      │
    │                             ┌─────┴──────────┐           │
    │                             │ Store in       │           │
    │                             │ wp_options:    │           │
    │                             │ • connection_id│           │
    │                             │ • token (enc.) │           │
    │                             │ • widget_key   │           │
    │                             │ • workspace    │           │
    │                             │ • widget config│           │
    │                             └─────┬──────────┘           │
    │                                   │                      │
    │  7. Redirect ?connected=1         │                      │
    │  <────────────────────────────────│                      │
    │                                   │                      │
    │  ┌──────────────────────┐         │                      │
    │  │ "Successfully        │         │                      │
    │  │  connected!" notice  │         │                      │
    │  │ + settings form      │         │                      │
    │  └──────────────────────┘         │                      │
    ▼                                   ▼                      ▼
```

---
*Generated with /ascii*
