Skip to content

Commit 32f22c7

Browse files
committed
add app files
1 parent d4c3c58 commit 32f22c7

26 files changed

Lines changed: 2389 additions & 1 deletion

‎app-client-starter-app‎

Lines changed: 0 additions & 1 deletion
This file was deleted.

‎app-client-starter-app/.DS_Store‎

16 KB
Binary file not shown.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Your app client, from https://publish.buffer.com/settings/api
2+
BUFFER_CLIENT_ID=your_client_id
3+
BUFFER_CLIENT_SECRET=your_client_secret
4+
5+
# Must match what you registered, character for character
6+
REDIRECT_URI=https://localhost:3000/callback
7+
8+
# Encrypts the session cookie; 32 characters minimum. Leave it empty locally and
9+
# the app generates one into .session-key on first boot. Required in production:
10+
# openssl rand -hex 32
11+
SESSION_SECRET=
12+
13+
PORT=3000
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: CI
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches: [main]
7+
8+
permissions:
9+
contents: read
10+
11+
jobs:
12+
verify:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v4
16+
- uses: actions/setup-node@v4
17+
with:
18+
node-version: 22
19+
cache: npm
20+
- run: npm ci
21+
- run: npm test
22+
- run: npm run lint

‎app-client-starter-app/.gitignore‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules/
2+
certs/
3+
.env
4+
.session-key
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Never upload the local TLS key, and let the platform install dependencies.
2+
certs/
3+
node_modules/
4+
.env
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Contributing
2+
3+
Keep this example small and copyable. New code should teach one clear Buffer App Client practice, include a test when it changes behavior, and avoid adding frameworks or dependencies unless they clarify the OAuth example.
4+
5+
Before opening a pull request, run `npm test` and `npm run lint`. Never commit `.env`, certificates, client secrets, sessions, or real tokens.

‎app-client-starter-app/LICENSE‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
MIT License
2+
3+
Copyright (c) 2026 Draft Queue contributors
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6+
7+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

‎app-client-starter-app/README.md‎

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# Draft Queue: a Buffer app client example
2+
3+
A small, runnable example of a third-party app built on the [Buffer API](https://developers.buffer.com).
4+
5+
6+
## What it does
7+
It's a small starter app called Draft Queue which covers key components of an app client:
8+
9+
1. A user connects their own Buffer account over OAuth 2.0 (Authorization Code + PKCE).
10+
2. The app lists the channels in their Buffer organization.
11+
3. The user picks a channel, and the app creates a **draft** post in that channel's queue.
12+
13+
Use it as a starting point for your own integration. Clone it, configure it with your own app client, build new features on top, or share it with your AI coding agent as a reference.
14+
15+
📘 **Tutorial:** [Creating Buffer Client Apps](https://example.com/TODO-tutorial-url) walks through this example step by step, from registering an app client to deploying it.
16+
17+
## Prerequisites
18+
19+
- Node.js 22
20+
- A [Buffer](https://buffer.com) account
21+
- A Buffer app client (client ID and secret). See the [authentication guide](https://developers.buffer.com/guides/authentication.html) for how to register one.
22+
- (Optional) Vercel or another hosting provider, if you want to deploy the app
23+
24+
## Setup
25+
26+
1. From the root of the repository, move into this sample:
27+
28+
```bash
29+
cd app-client-starter-app
30+
```
31+
32+
2. Install dependencies:
33+
34+
```bash
35+
npm install
36+
```
37+
38+
3. Create your environment file:
39+
40+
```bash
41+
cp .env.example .env
42+
```
43+
44+
Then fill in the values:
45+
46+
| Variable | Purpose |
47+
| --- | --- |
48+
| `BUFFER_CLIENT_ID` | Your app client ID from Buffer. |
49+
| `BUFFER_CLIENT_SECRET` | Required for a confidential client. Never expose it to the browser or commit it. |
50+
| `SESSION_SECRET` | At least 32 characters. Generate one with `openssl rand -hex 32`. Optional locally, required in production. |
51+
| `REDIRECT_URI` | Optional locally. If set, it must exactly match the redirect URI registered for your app client. |
52+
53+
4. Generate a self-signed certificate for local HTTPS:
54+
55+
```bash
56+
npm run certs
57+
```
58+
59+
Buffer doesn't accept `http://localhost` redirect URIs, so the dev server runs over HTTPS. If you skip this step, `npm start` generates the certificate on first run.
60+
61+
## Run it locally
62+
63+
```bash
64+
npm start
65+
```
66+
67+
Open `https://localhost:3000` and accept the self-signed development certificate in your browser.
68+
69+
To run the tests and syntax checks:
70+
71+
```bash
72+
npm test
73+
npm run lint
74+
```
75+
76+
## Project structure
77+
78+
| Path | What it holds |
79+
| --- | --- |
80+
| `lib/` | The app itself: OAuth and GraphQL (`buffer.js`), the session cookie (`session.js`), Express routes (`app.js`), and configuration (`config.js`). |
81+
| `public/` | The single-page UI. |
82+
| `server.js` | Local HTTPS dev server. |
83+
| `api/index.js`, `vercel.json` | Serverless entry point and routing, using Vercel as an example host. |
84+
| `test/` | Regression tests for the protocol and security-critical helpers. |
85+
| `docs/` | Architecture notes and the production OAuth guide. |
86+
| `scripts/` | Generates the self-signed certificate for local HTTPS. |
87+
88+
## What this example covers
89+
90+
- **OAuth 2.0 with PKCE:** the full Authorization Code flow with PKCE. It sends the user to Buffer to authorize the app, handles the redirect back, and exchanges the authorization code for tokens. See `lib/buffer.js`.
91+
- **GraphQL requests:** authenticated calls to the Buffer GraphQL API. The app reads the user's organization and channels, then runs a mutation that creates a draft post in a channel's queue.
92+
- **Refresh tokens:** the app requests the `offline_access` scope, so Buffer returns a refresh token alongside the access token. When the access token expires, the app renews it without asking the user to sign in again. Both tokens are sealed inside an HttpOnly cookie, so browser JavaScript can never read them.
93+
- **Staying within rate limits:** the app reads the rate limit headers on each response and uses them to stay within the limits applied to the client.
94+
- **Deployment:** a working setup for Vercel (`api/index.js` and `vercel.json`) shows how to run the same app as a serverless deployment. You can adapt it to any Node.js host.
95+
96+
## Further reading
97+
98+
- [Buffer developer docs](https://developers.buffer.com)
99+
- [Architecture notes](docs/architecture.md)
100+
- [Production OAuth guide](docs/production-oauth.md)
101+
102+
## Support and contributing
103+
104+
This sample is provided as-is for educational purposes and isn't covered by Buffer's product support or service-level agreements. If you find a bug or something out of date, please [open an issue](../../../issues). See the [repository README](../README.md#contributing) for how we handle contributions.
105+
106+
## License
107+
108+
This sample is licensed under the MIT License. See the [LICENSE](../LICENSE) file at the root of the repository.

‎app-client-starter-app/SECURITY.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Security policy
2+
3+
Do not file public issues containing Buffer tokens, client secrets, session cookies, or account data. Report a suspected vulnerability privately to the repository owner and revoke any exposed Buffer credentials immediately from [Buffer Settings → API](https://publish.buffer.com/settings/api).

0 commit comments

Comments
 (0)