infipostdocs
CLI

Self-hosting the CLI auth server

Run your own OAuth2 device-flow server for the Infipost CLI login

postiz auth:login uses the hosted auth server at cli-auth.infipost.com by default. That works fine against a self-hosted Infipost too, since the server only mediates the device flow. Run your own if you would rather no third party sat in the login path.

The auth server mediates the OAuth2 device flow so CLI users can authenticate without needing client credentials of their own.

Prerequisites

  • Node.js >= 18
  • PostgreSQL

How It Works

text
CLI                        Auth Server                    Infipost
 |                              |                           |
 |-- POST /device/code ------->|                           |
 |<-- device_code + user_code --|                           |
 |                              |                           |
 |  User opens browser ------->|                           |
 |  Enters code                |                           |
 |                              |-- redirect to OAuth ----->|
 |                              |<-- callback with code ----|
 |                              |-- exchange for token ---->|
 |                              |<-- access_token ----------|
 |                              |  (stored in Postgres)     |
 |                              |                           |
 |  POST /device/token (poll) >|                           |
 |<-- access_token ------------|                           |

1. Clone the Repository

The auth server lives in the infipost-agent repository:

bash
git clone https://github.com/phamdacthanh197/infipost-agent.git
cd infipost-agent/server

2. Create an OAuth App in Infipost

Go to Infipost Settings > Developer > OAuth Apps and create a new app. Set the callback URL to:

text
https://your-server-domain.com/device/callback

3. Set Up Postgres

Create a database. The server auto-creates the device_requests table on startup.

4. Configure Environment

bash
export DATABASE_URL="postgresql://user:password@localhost:5432/postiz_auth"
export POSTIZ_OAUTH_CLIENT_ID="pca_xxx"
export POSTIZ_OAUTH_CLIENT_SECRET="pcs_xxx"
export SERVER_URL="https://your-server-domain.com"
VariableRequiredDefaultDescription
DATABASE_URLYes-Postgres connection string
POSTIZ_OAUTH_CLIENT_IDYes-OAuth app client ID from Infipost
POSTIZ_OAUTH_CLIENT_SECRETYes-OAuth app client secret from Infipost
PORTNo3111Server port
SERVER_URLNohttp://localhost:{PORT}Public URL of this server
POSTIZ_FRONTEND_URLNohttps://app.infipost.asiaInfipost frontend URL for OAuth redirects
POSTIZ_API_URLNohttps://api.infipost.asiaInfipost API URL for token exchange

5. Run the Server

bash
pnpm install

# Development
pnpm dev

# Production
pnpm build
pnpm start:prod

6. Point the CLI to Your Server

bash
export POSTIZ_AUTH_SERVER="https://your-server-domain.com"
postiz auth:login

Server Endpoints

MethodPathDescription
POST/device/codeStart a new device flow. Returns device_code, user_code, and verification_uri.
GET/device/verifyBrowser page where the user enters their code.
POST/device/verifyValidates user code and redirects to Infipost OAuth.
GET/device/callbackInfipost redirects here after authorization. Exchanges auth code for token.
POST/device/tokenCLI polls this with device_code. Returns token when auth completes.
GET/healthHealth check.

Deployment

Any platform that runs Node.js and can connect to Postgres works, Railway, Fly.io, Render, VPS, etc.

The server is stateless beyond Postgres, so it scales horizontally. Run multiple instances behind a load balancer if needed.