/** * Optional GitHub Device-Flow authentication (R05, protocol re-checked R06). * * Architecture decisions (frozen): * - Device Flow only: the flow itself needs NO redirect URL and NO client * secret — the Quick Tunnel hostname changes every start, which classic * callback OAuth cannot follow. NOTE (R06, current GitHub rules): the * OAuth App's **Authorization callback URL is still REQUIRED at app * creation** (Device Flow simply never uses it), and **Enable Device * Flow must be explicitly turned ON** for the app; the token exchange * never sends a client_secret; * - one official public Client ID is embedded (Client ID is not a secret); * the maintainer's official OAuth App (Enable Device Flow ON) is the * default, and advanced users / forks can override with the * `githubClientId` config; * - scope: NONE. GitHub's device flow with an empty scope still returns * the authenticated user's identity from `/user` (id + login), which is * all we need. No repo/write/org/gist/workflow permissions are ever * requested; * - the GitHub access token exists ONLY in memory during the exchange and * is discarded immediately after the identity lookup. It is never * written to logs, disk, config, or browser storage; * - the identity that grants access is the IMMUTABLE numeric GitHub user * id (login is display-only); * - every flow is short-lived (GitHub expires_in + margin), bounded * (max concurrent flows + a global start rate) and cancellable, so a * public attacker cannot exhaust memory or GitHub API rate by starting * unlimited flows; * - remote login NEVER grants management power: it only issues OUR Device * Session (the same one the pairing code issues) after the identity * matches an allowed id. Revocation/device management stay identical. */ import type { GatewayLogger } from '../vendor/dsh-remote-web-gateway/dist/logger.js'; import type { PairingGithubFlowStart, PairingGithubPollResult } from '../vendor/dsh-remote-web-gateway/dist/pairing-routes.js'; export interface BoundIdentity { readonly githubUserId: number; /** Display-only: never used as a security identity. */ readonly githubLogin: string; readonly boundAt: number; } /** * The project's official public OAuth App Client ID. * * R06: the project maintainer created the official "DSH Remote Web Gateway" * OAuth App with **Enable Device Flow** turned ON and provided this public * Client ID (a Client ID is NOT a secret; we never use, generate, or ask for * a Client Secret). It is embedded so ordinary users can bind GitHub without * creating their own OAuth App. Advanced users / forks can still override it * via the `githubClientId` plugin config. * * Registration requirements (per current GitHub rules): the OAuth App's * Authorization callback URL must be filled at creation (Device Flow never * uses it), Enable Device Flow must be ON, and the device-flow token * exchange sends no client_secret. */ export declare const DEFAULT_GITHUB_CLIENT_ID: string | undefined; export interface GithubAuthOptions { /** * OAuth App client id; undefined falls back to the built-in official * client id (also undefined until the maintainer fills it in). */ readonly clientId: string | undefined; /** Initial allow-list from config (may be empty; the bind UI adds one). */ readonly allowedUserIds: readonly number[]; /** Absolute state file for the bound identity (github-auth.json). */ readonly stateFile: string; readonly logger: GatewayLogger; readonly now?: () => number; readonly fetchFn?: (url: string, init?: RequestInit) => Promise; readonly deviceCodeUrl?: string; readonly tokenUrl?: string; readonly apiBase?: string; readonly maxConcurrentFlows?: number; readonly startRateLimit?: number; readonly flowTtlMs?: number; } export interface GithubStatusView { /** * GitHub Device Flow is CONFIGURED: a valid Client ID exists (the embedded * official default, or an override). Distinct from bound / availability. */ readonly configured: boolean; /** This computer has a BOUND allowed GitHub identity. */ readonly bound: boolean; /** * Remote GitHub login (public /pair) is AVAILABLE: configured AND at least * one allowed identity exists (config allow-list or the bound identity). * A fresh install is configured but NOT available until an identity is * bound — the DSH settings must show 未绑定 + [绑定 GitHub], never * "waiting for a Client ID". */ readonly remoteLoginAvailable: boolean; readonly githubUserId?: number; readonly githubLogin?: string; readonly boundAt?: number; } export interface GithubFlowView { readonly flowId: string; readonly verificationUri: string; readonly userCode: string; readonly expiresAt: number; readonly intervalMs: number; } export type GithubPollResult = { readonly status: 'pending'; readonly intervalMs: number; } | { readonly status: 'slow_down'; readonly intervalMs: number; } | { readonly status: 'ready'; readonly githubUserId: number; readonly login: string; } | { readonly status: 'denied' | 'expired' | 'not-found' | 'wrong-user'; }; export interface GithubAuthService { readonly enabled: boolean; status(): Promise; /** Host-side bind flow (DSH Settings). */ bindStart(): Promise; bindPoll(flowId: string): Promise; /** Remote login flow (public /pair page) — identity must be allowed. */ remoteStart(): Promise; remotePoll(flowId: string): Promise; cancel(flowId: string): Promise; unbind(): Promise; /** Whether remote login can be offered at all. */ readonly remoteEnabled: boolean; } export declare function createGithubAuthService(options: GithubAuthOptions): GithubAuthService;