@heyhru/server-ext-feishu
v0.1.1
Published
Feishu (Lark) OAuth helpers: build authorize URL and exchange code for user info
Readme
@heyhru/server-ext-feishu
Feishu (Lark) OAuth helpers — pure HTTP wrappers around the Feishu passport endpoints. No Fastify coupling, no env reads; the caller passes credentials explicitly.
Install
pnpm add @heyhru/server-ext-feishuAPI
FeishuConfig
interface FeishuConfig {
appId: string;
appSecret: string;
redirectUri: string;
}buildFeishuAuthUrl(state, cfg): string
Build the authorize URL the user should be redirected to. state is an opaque CSRF token the caller is responsible for verifying on callback.
exchangeFeishuCode(code, cfg): Promise<FeishuUserInfo>
Exchange the authorization code returned by the Feishu callback for a user-access token, then call authen/v1/user_info and return the user record:
interface FeishuUserInfo {
open_id: string;
union_id: string;
name: string;
avatar_url: string;
email: string;
}Throws Error with a human-readable message if either endpoint fails.
Usage
import { buildFeishuAuthUrl, exchangeFeishuCode } from "@heyhru/server-ext-feishu";
const cfg = {
appId: process.env.FEISHU_APP_ID!,
appSecret: process.env.FEISHU_APP_SECRET!,
redirectUri: process.env.FEISHU_REDIRECT_URI!,
};
// Step 1: send the user to Feishu
const url = buildFeishuAuthUrl(randomState, cfg);
// Step 2: handle the callback
const userInfo = await exchangeFeishuCode(code, cfg);