Skip to content

Commit 29d59cb

Browse files
committed
docs: add YouTube OAuth provisioning guide
1 parent 97bf37b commit 29d59cb

2 files changed

Lines changed: 126 additions & 8 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
All notable project changes are recorded here. The README shows only the most recent entry.
44

5+
## 2026-07-06 - YouTube Provisioning Documentation
6+
7+
- Added Google Cloud, YouTube Data API, Google Auth Platform, OAuth client, device-code authorization, validation, and common-error instructions for fresh deployments.
8+
- Documented the `org_internal`, `invalid_client`, testing-mode token expiry, and channel-permission failure modes observed during setup.
9+
510
## 2026-07-06 - Executive Summary Documentation
611

712
- Expanded the README into an executive summary covering architecture, runtime process flow, operational commands, recovery behavior, and caveats.

README.md

Lines changed: 121 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -213,27 +213,141 @@ YTA_OBS_SOURCE_NAME=Camera RTSP
213213

214214
The OBS service file supplies the reusable YouTube RTMPS server and stream key. If YouTube AutoEncoder creates a reusable stream through the API, it updates that service file.
215215

216-
## YouTube Authorization
216+
## YouTube API and OAuth Provisioning
217217

218-
Create a Google OAuth client and place the downloaded JSON at:
218+
YouTube AutoEncoder needs OAuth, not just an API key. The service creates and manages private YouTube resources such as `liveBroadcast` and `liveStream`, binds them together, and transitions broadcasts through `testing`, `live`, and `complete`. Those operations must be authorized by the Google account that owns or manages the YouTube channel.
219+
220+
Official references:
221+
222+
- [YouTube Live Streaming API Overview](https://developers.google.com/youtube/v3/live/getting-started)
223+
- [Obtaining authorization credentials](https://developers.google.com/youtube/registering_an_application)
224+
- [OAuth device flow for limited-input devices](https://developers.google.com/youtube/v3/guides/auth/devices)
225+
- [Google Auth Platform audience settings](https://support.google.com/cloud/answer/15549945)
226+
- [Google Auth Platform OAuth clients](https://support.google.com/cloud/answer/15549257)
227+
228+
### 1. Prepare the YouTube Channel
229+
230+
1. Sign in to YouTube Studio with the Google account that owns or manages the channel.
231+
2. Confirm that live streaming is enabled for the channel. New channels, restricted channels, or channels with policy holds may not be able to stream immediately.
232+
3. If the channel is a Brand Account, authorize with a Google account that can manage that Brand Account.
233+
234+
### 2. Create or Select a Google Cloud Project
235+
236+
1. Open the [Google Cloud Console](https://console.cloud.google.com/).
237+
2. Create a new project for the encoder, or select an existing project dedicated to this deployment.
238+
3. Open **APIs & Services > Library**.
239+
4. Enable **YouTube Data API v3** for the project.
240+
241+
The Live Streaming API is exposed through the YouTube Data API v3 for the broadcast and stream operations this project uses.
242+
243+
### 3. Configure Google Auth Platform
244+
245+
Open **Google Auth Platform** for the same project and configure the app before creating the OAuth client.
246+
247+
Audience:
248+
249+
- Use **External** when the Google account authorizing the YouTube channel may be outside your Google Cloud Organization.
250+
- Use **Internal** only when every authorizing account is in the same Google Cloud Organization as the project.
251+
- If you see `org_internal` during authorization, the OAuth app is limited to organization users. Change the audience to External or authorize with an account inside that organization.
252+
253+
Publishing status:
254+
255+
- **Testing** is fine for initial setup. Add the streaming Google account as a test user before authorizing.
256+
- Testing-mode authorizations for non-basic scopes can expire after seven days, including refresh tokens. For unattended deployments, move the app to **In production** and complete any required Google verification.
257+
- In production, users may see an unverified-app warning until Google verifies the app and requested scopes.
258+
259+
Data access / scopes:
260+
261+
- Add `https://www.googleapis.com/auth/youtube`.
262+
- This scope is broad, but it is the scope this project uses to manage YouTube Live broadcasts and streams.
263+
- Avoid adding extra scopes unless the code actually needs them; additional sensitive or restricted scopes can increase verification requirements.
264+
265+
Branding:
266+
267+
- Use an app name that identifies the deployment, such as `YouTube AutoEncoder`.
268+
- Provide a monitored support email.
269+
- Add privacy policy, terms, and authorized domain information if Google requires them for your app state.
270+
271+
### 4. Create the OAuth Client
272+
273+
1. Open **Google Auth Platform > Clients**.
274+
2. Click **Create client**.
275+
3. Choose **TVs and Limited Input devices** where available. This matches the device-code flow used by `youtube-autoencoder-api authorize`.
276+
4. Name the client, for example `YouTube AutoEncoder`.
277+
5. Create the client and download the JSON credentials.
278+
279+
If the console only offers a generic installed-app flow in your environment, use the device or installed/native option intended for command-line or limited-input devices. If authorization later fails with `invalid_client`, create a new client with the explicit **TVs and Limited Input devices** application type.
280+
281+
### 5. Install the OAuth Client JSON
282+
283+
Copy the downloaded JSON to the service user's config directory:
219284

220285
```text
221286
~/.config/youtube-autoencoder/google-oauth-client.json
222287
```
223288

224-
Run:
289+
Lock down the file:
290+
291+
```bash
292+
chmod 600 ~/.config/youtube-autoencoder/google-oauth-client.json
293+
```
294+
295+
The file contains OAuth client credentials. Do not commit it, paste it into issue trackers, or store it in a world-readable location.
296+
297+
### 6. Authorize the Encoder
225298

226299
```bash
227300
youtube-autoencoder-api authorize
228301
```
229302

230-
Open the displayed device-flow URL, enter the code, and approve access for the YouTube channel account. The refresh token is stored in:
303+
The command prints a verification URL and user code. Open the URL on any browser-capable device, enter the code, and approve access with the Google account that owns or manages the target YouTube channel.
304+
305+
After approval, the helper stores the OAuth token cache at:
231306

232307
```text
233308
~/.config/youtube-autoencoder/youtube-token.json
234309
```
235310

236-
Keep both files private.
311+
Lock down the token file:
312+
313+
```bash
314+
chmod 600 ~/.config/youtube-autoencoder/youtube-token.json
315+
```
316+
317+
Keep this file private. It contains the refresh token used for unattended operation.
318+
319+
### 7. Validate the YouTube API Setup
320+
321+
If you already have an OBS-compatible `service.json` with a YouTube stream key:
322+
323+
```bash
324+
youtube-autoencoder-api status
325+
```
326+
327+
For a fresh setup where the reusable YouTube stream should be created automatically, make sure the service user can write the configured OBS service file and set:
328+
329+
```text
330+
YTA_YOUTUBE_CREATE_STREAM=true
331+
```
332+
333+
Then run an API-managed visible test after the rest of the encoder config is in place:
334+
335+
```bash
336+
youtube-autoencoder-api run-visible-test --duration 900 --privacy unlisted --create-stream
337+
```
338+
339+
This validates OAuth, the reusable stream, broadcast creation, stream binding, ingest detection, transition to `testing`, transition to `live`, and broadcast completion.
340+
341+
### Common Authorization Problems
342+
343+
| Symptom | Likely cause | Fix |
344+
| --- | --- | --- |
345+
| `org_internal` | OAuth app audience is Internal and the authorizing account is outside the project's Google Cloud Organization. | Change the app audience to External, or authorize with an account inside the organization. |
346+
| `invalid_client` | OAuth client type does not support the device-code flow. | Create a client for TVs and Limited Input devices, then replace `google-oauth-client.json`. |
347+
| `authorization_pending` | The browser approval has not completed yet. | Finish the device-code flow; the CLI will keep polling until the code expires. |
348+
| `slow_down` | Polling is too frequent. | The helper backs off automatically. |
349+
| Token works briefly then expires | App is still in Testing mode. | Add the correct test user for setup, then move the app to In production for unattended use and complete required verification. |
350+
| API calls fail despite valid OAuth | The account does not own/manage the YouTube channel, live streaming is not enabled, or quota/policy blocks the operation. | Reauthorize with the right channel account, enable live streaming, and check project quota and YouTube Studio restrictions. |
237351

238352
## Operations
239353

@@ -292,10 +406,9 @@ youtube-autoencoder-api complete
292406

293407
Only the most recent changelog entry is shown here. See `CHANGELOG.md` for full history.
294408

295-
### 2026-07-06 - Executive Summary Documentation
409+
### 2026-07-06 - YouTube Provisioning Documentation
296410

297-
- Expanded the README into an executive summary covering architecture, runtime process flow, operational commands, recovery behavior, and caveats.
298-
- Added a standalone changelog so the README can show only the newest entry.
411+
- Added Google Cloud, YouTube Data API, Google Auth Platform, OAuth client, device-code authorization, validation, and common-error instructions for fresh deployments.
299412

300413
## Repository Layout
301414

0 commit comments

Comments
 (0)