diff --git a/x-api/activity/introduction.mdx b/x-api/activity/introduction.mdx index dda20f66b..f739fa3b1 100644 --- a/x-api/activity/introduction.mdx +++ b/x-api/activity/introduction.mdx @@ -337,10 +337,9 @@ Private events are activities that require explicit user consent through OAuth a - Broadcast chats (`broadcast.chat`, `broadcast.chat.remove`) — requires the `broadcast.read` scope **Authentication requirements for private events:** -- The user must authenticate your application via OAuth 2.0 -- Your application must obtain appropriate OAuth scopes -- The user must explicitly grant permission for your app to access these events -- Subscriptions for private events can only be created for users who have authorized your application +- **OAuth 2.0 user context (recommended):** The user authorizes your application via OAuth 2.0 with the scope required for each event type (for example `dm.read` for `chat.*` and `dm.*`). +- **OAuth 1.0a user context (existing apps):** For `chat.*` and `dm.*` events (such as `chat.received`, `chat.sent`, and `chat.conversation.join`), existing apps can also authenticate with an **OAuth 1.0a user token** configured with **Read, Write, and Direct Messages** permissions for subscription management (`POST`/`GET`/`PUT`/`DELETE /2/activity/subscriptions`) and event delivery on both webhooks and `GET /2/activity/stream` (where the stream connection itself uses your app's Bearer token). OAuth 1.0a is scheduled for retirement on January 31, 2027 — see [Migrate from OAuth 1.0a to OAuth 2.0](/fundamentals/authentication/oauth-2-0/oauth-1-0a-token-exchange). +- Subscriptions for private events can only be created for users who have authorized your application, and the authenticating user must match `filter.user_id`. ## Subscription expiration diff --git a/xchat/getting-started.mdx b/xchat/getting-started.mdx index 47f49043f..ae7a931de 100644 --- a/xchat/getting-started.mdx +++ b/xchat/getting-started.mdx @@ -17,8 +17,9 @@ X Chat apps use two pieces together: **Prerequisites** -- [Developer account](https://developer.x.com/en/portal/petition/essential/basic-info) and an app configured for OAuth 2.0 -- User access token with `dm.read`, `dm.write`, `tweet.read`, and `users.read` +- [Developer account](https://developer.x.com/en/portal/petition/essential/basic-info) and an app configured for OAuth 2.0 (recommended) or an existing app with OAuth 1.0a enabled +- **OAuth 2.0:** User access token with `dm.read`, `dm.write`, `tweet.read`, and `users.read` (plus `media.write` if uploading or downloading media) +- **OAuth 1.0a (existing apps):** User access token and token secret from an app with **Read, Write, and Direct Messages** permissions. OAuth 1.0a works across all X Chat endpoints (including `GET /2/users/{id}/public_keys` and `GET /2/users/public_keys`) until OAuth 1.0a retires on January 31, 2027 — see [Migrate from OAuth 1.0a to OAuth 2.0](/fundamentals/authentication/oauth-2-0/oauth-1-0a-token-exchange). --- @@ -83,7 +84,7 @@ X Chat apps use two pieces together: -Create an API client with your **user** OAuth 2.0 access token: +Create an API client with your **user** OAuth 2.0 access token (or sign requests with an OAuth 1.0a user token with **Read, Write, and Direct Messages** permissions): diff --git a/xchat/introduction.mdx b/xchat/introduction.mdx index bfdbc50dd..6dcb8891b 100644 --- a/xchat/introduction.mdx +++ b/xchat/introduction.mdx @@ -44,7 +44,11 @@ Grouped under **API reference** in the sidebar, including: ## Auth notes -Use **OAuth 2.0 user context** with DM-related scopes (`dm.read`, `dm.write`, `users.read`, `tweet.read`, **`media.write` for both media uploads and downloads**, and `offline.access` for refresh tokens). X Chat activity for a user requires that user's authorization. Secure key backup configuration is returned on **your** public-key record (`juicebox_config` field); see [Getting Started](/xchat/getting-started) and the full scope matrix in [Migrate from Legacy DMs](/xchat/migrate-from-legacy-dms#2-authentication-and-oauth-20-scope-matrix). +Use **OAuth 2.0 user context** (recommended) with DM-related scopes (`dm.read`, `dm.write`, `users.read`, `tweet.read`, **`media.write` for both media uploads and downloads**, and `offline.access` for refresh tokens). + +**OAuth 1.0a user tokens** are also supported on all X Chat and public-key endpoints (`/2/chat/*`, `/2/users/{id}/public_keys`, `/2/users/public_keys`) as well as X Activity API `chat.*` subscriptions and event delivery, provided the app has **Read, Write, and Direct Messages** permissions. This lets existing apps migrate to X Chat before moving to OAuth 2.0 (OAuth 1.0a is scheduled for retirement on January 31, 2027 — see [Migrate from OAuth 1.0a to OAuth 2.0](/fundamentals/authentication/oauth-2-0/oauth-1-0a-token-exchange)). + +X Chat activity for a user requires that user's authorization. Secure key backup configuration is returned on **your** public-key record (`juicebox_config` field); see [Getting Started](/xchat/getting-started) and the full auth matrix in [Migrate from Legacy DMs](/xchat/migrate-from-legacy-dms#2-authentication-and-oauth-20-scope-matrix). --- diff --git a/xchat/media.mdx b/xchat/media.mdx index e2faba3d9..8a3cfc3a4 100644 --- a/xchat/media.mdx +++ b/xchat/media.mdx @@ -8,7 +8,7 @@ keywords: ["X Chat media", "encrypted images", "file attachments", "encrypt_file Images and other files are encrypted client-side with the Chat XDK (`encrypt_file` / `decrypt_file`), uploaded via the **`/2/chat/media/upload`** routes (sidebar **API reference → Media**), and referenced by **`media_hash_key`** inside `encrypt_message`. -**`media.write` is required for both uploads and downloads.** All four `/2/chat/media/*` routes — including `GET /2/chat/media/{conversation_id}/{media_hash_key}` — require the `media.write` OAuth 2.0 scope, not `dm.read`. +**`media.write` is required for both uploads and downloads with OAuth 2.0.** All four `/2/chat/media/*` routes — including `GET /2/chat/media/{conversation_id}/{media_hash_key}` — require the `media.write` OAuth 2.0 scope, not `dm.read`. Existing apps using **OAuth 1.0a** user tokens (with **Read, Write, and Direct Messages** permissions) are also supported on all four `/2/chat/media/*` routes until OAuth 1.0a retires on January 31, 2027. Use hyphenated conversation IDs in URL paths (`:` → `-`) and canonical colon IDs (`min:max` or `g…`) in upload JSON bodies. Prefer MIME and dimensions from **decrypted** bytes. Maximum encrypted file size is **100 MB**. diff --git a/xchat/migrate-from-legacy-dms.mdx b/xchat/migrate-from-legacy-dms.mdx index 9bd1ab538..a255f7633 100644 --- a/xchat/migrate-from-legacy-dms.mdx +++ b/xchat/migrate-from-legacy-dms.mdx @@ -14,7 +14,7 @@ Moving from Legacy Direct Messages (`v1.1 direct_messages/*`, `v2 /2/dm_events`, | Aspect | Legacy DMs (v1.1 / v2) | X Chat API (`/2/chat`) | |:-------|:-----------------------|:-----------------------| | **Encryption** | Server-side plaintext (`text`) | End-to-end encrypted & signed via the [Chat XDK](/xchat/xchat-xdk); X relays ciphertext only | -| **Credentials** | OAuth token only | OAuth 2.0 user token **plus** P-256 identity & signing private keys (backed up via Juicebox PIN or exported key blob) | +| **Credentials** | OAuth token only | User OAuth token (OAuth 2.0 or OAuth 1.0a with Read, Write, and Direct Messages) **plus** P-256 identity & signing private keys (backed up via Juicebox PIN or exported key blob) | | **Starting a 1:1** | One send call | Conversation-key handshake (`POST /2/chat/conversations/{id}/keys`) first if no key exists, then send | | **Reading history** | Cross-conversation `GET /2/dm_events` feed | No global feed — list `GET /2/chat/conversations` (`?start_time=`), then page `GET /2/chat/conversations/{id}/events` | | **Media** | Uploaded once via general media upload; server-readable | Client-encrypted (`encrypt_file`), uploaded in chunks, downloaded as ciphertext (`media.write` required for **both** upload and download) | @@ -51,7 +51,18 @@ Every `/2/chat/*` and `/2/users/*/public_keys` route requires **user-context aut tweet.read users.read dm.read dm.write media.write offline.access ``` -If you still sign X Chat calls with OAuth 1.0a during migration, configure your app with **Read, Write and Direct Messages** permissions and reissue user tokens — otherwise routes return `403 oauth1-permissions`. +### Using OAuth 1.0a during migration + +Existing apps do **not** need to migrate to OAuth 2.0 before migrating to X Chat. **OAuth 1.0a user tokens** are supported on: + +- **All public `/2/chat/*` and `/2/users/*/public_keys` endpoints** — including public key retrieval (`GET /2/users/{id}/public_keys`, `GET /2/users/public_keys`), key registration, conversation key initialization, sending/reading messages, events, typing/read indicators, group management, message requests, settings, and all four `/2/chat/media/*` upload/download routes. +- **X Activity API `chat.*` subscriptions and delivery** — creating, listing, updating, and deleting individual subscriptions (`/2/activity/subscriptions`), managing webhooks (`/2/webhooks`), and receiving `chat.received`, `chat.sent`, and other `chat.*` events via webhooks or `GET /2/activity/stream`. + +Configure your app with **Read, Write, and Direct Messages** permissions and reissue user tokens if you changed permissions — otherwise routes return `403 oauth1-permissions` and X Activity API drops `chat.*` deliveries. + +Only app-level utility routes (`GET /2/activity/stream`, batch `DELETE /2/activity/subscriptions`, and `POST /2/webhooks/replay`) require an **OAuth 2.0 App-Only Bearer token**; these use your app's bearer token and do **not** require end-user OAuth 2.0 tokens. + +OAuth 1.0a is scheduled for retirement on **January 31, 2027**. When you are ready to move user tokens to OAuth 2.0 without asking users to re-authorize, use the server-side token exchange in [Migrate from OAuth 1.0a to OAuth 2.0](/fundamentals/authentication/oauth-2-0/oauth-1-0a-token-exchange). --- @@ -104,7 +115,7 @@ If you still sign X Chat calls with OAuth 1.0a during migration, configure your ## 5. Pre-cutover verification checklist - [ ] **Zero legacy DM calls remaining:** Audit and remove `/2/dm_events`, `/2/dm_conversations`, v1.1 `direct_messages/*`, `media_category=dm_*`, Account Activity DM webhooks, and XAA `dm.*` subscriptions. -- [ ] **Auth & scopes verified:** OAuth 2.0 user context with `tweet.read users.read dm.read dm.write media.write offline.access`; App-Only Bearer used **only** on `GET /2/activity/stream`. Media download succeeds (verifies `media.write`). +- [ ] **Auth & scopes verified:** User-context auth configured — either OAuth 2.0 (`tweet.read users.read dm.read dm.write media.write offline.access`) or OAuth 1.0a (**Read, Write, and Direct Messages**); App-Only Bearer used **only** for app-level routes (`GET /2/activity/stream`, batch subscription delete, webhook replay). Media download succeeds (verifies `media.write` on OAuth 2.0 or DM permission on OAuth 1.0a). - [ ] **Key custody & safety verified:** Key architecture chosen per [Handling private keys](/xchat/handling-private-keys) (B2B partner approval obtained if holding keys for third-party business accounts); brand account's official X app still works after onboarding; no PIN persisted or logged; Juicebox `unlock()` never auto-retried on failure; `public_key_version` rotation monitored. - [ ] **Core round-trips tested:** New 1:1 key handshake → encrypted send (retry reuses identical payload, produces one message) → `chat.received` / `chat.sent` / `chat.conversation.join` delivery & decrypt → encrypted media upload/download round-trip → message request accept → group create. - [ ] **Allowlist cutover (Enterprise):** After cutover, coordinate with your X account representative to remove the app from the enterprise legacy-DM allowlist so new 1:1s encrypt cleanly. diff --git a/xchat/real-time-events.mdx b/xchat/real-time-events.mdx index fe2f2a70d..b5d90cea2 100644 --- a/xchat/real-time-events.mdx +++ b/xchat/real-time-events.mdx @@ -43,7 +43,7 @@ Typing indicators and read receipts no longer arrive as separate webhook types - `PUT /2/activity/subscriptions/{subscription_id}`: update - `DELETE /2/activity/subscriptions/{subscription_id}` or `DELETE /2/activity/subscriptions?ids=`: delete -Request bodies and required scopes are defined in the OpenAPI operation for each route. Creating an X Activity API (XAA) subscription requires **user-context authorization** (OAuth 2.0 user context with `dm.read` for chat events) for the user whose activity you monitor. +Request bodies and required scopes are defined in the OpenAPI operation for each route. Creating an X Activity API (XAA) subscription for `chat.*` events requires **user-context authorization** for the user whose activity you monitor — either an **OAuth 2.0 user token** with `dm.read` (recommended) or an **OAuth 1.0a user token** from an app with **Read, Write, and Direct Messages** permissions. OAuth 1.0a user tokens with Read, Write, and Direct Messages permissions also satisfy delivery authorization for `chat.received`, `chat.sent`, and other `chat.*` events on both webhooks and `GET /2/activity/stream` (the stream connection itself uses your app's Bearer token, and does not require end-user OAuth 2.0 tokens). Batch deletion (`DELETE /2/activity/subscriptions?ids=`) and webhook replay (`POST /2/webhooks/replay`) likewise use your app's Bearer token; single-subscription and webhook CRUD routes accept OAuth 1.0a user tokens as well. **Webhooks:** if you terminate events on your HTTPS endpoint, register a webhook with `POST /2/webhooks`, pass CRC challenges, then create your activity subscriptions with `POST /2/activity/subscriptions`, referencing your `webhook_id` (see Webhooks and Activity operations in OpenAPI). Use `POST /2/webhooks/replay` to replay missed webhook deliveries. Note that `payload.conversation_id` arrives in canonical colon form (`min:max` for 1:1s) — replace `:` with `-` before placing it in URL paths. diff --git a/xchat/xchat-xdk.mdx b/xchat/xchat-xdk.mdx index 249361518..d90b47136 100644 --- a/xchat/xchat-xdk.mdx +++ b/xchat/xchat-xdk.mdx @@ -5,7 +5,7 @@ description: "Meet the Chat XDK, the library that handles keys, encryption, decr keywords: ["Chat XDK", "chat-xdk", "encryption SDK", "key management", "signing", "SDK reference"] --- -The **Chat XDK** handles key management, encryption, decryption, and signing for X Chat. It does **not** call the X HTTP API: pair it with the [Python](/xdks/python/overview), [TypeScript](/xdks/typescript/overview), [Java](/xdks/java/overview), or [C#](/xdks/csharp/overview) **XDK**, or with HTTPS and a user access token. +The **Chat XDK** handles key management, encryption, decryption, and signing for X Chat. It does **not** make authenticated X HTTP API calls (including public key retrieval): your application calls endpoints such as `GET /2/users/{id}/public_keys` and `/2/chat/*` via the [Python](/xdks/python/overview), [TypeScript](/xdks/typescript/overview), [Java](/xdks/java/overview), or [C#](/xdks/csharp/overview) **XDK** or HTTPS using either an **OAuth 2.0** user access token or an **OAuth 1.0a** user token (**Read, Write, and Direct Messages** permissions), and passes the returned keys and payloads into the Chat XDK. App walkthrough: [Getting Started](/xchat/getting-started). Sample bots: [chat-xdk/examples](https://github.com/xdevplatform/chat-xdk/tree/main/examples).