# Pinme Auth

Use when a PinMe project (Worker TypeScript) needs to integrate user authentication, ...

- Repository: https://github.com/glitternetwork/pinme (3753 stars)
- Category: Engineering
- License: MIT
- Last updated: 2026-09-12
- Runs scripts: no, instructions only

## Install

Claude Code: `npx skills add glitternetwork/pinme --skill pinme-auth -g -a claude-code -y`
Codex: `npx skills add glitternetwork/pinme --skill pinme-auth -g -a codex -y`
Cursor: `npx skills add glitternetwork/pinme --skill pinme-auth -g -a cursor -y`
Gemini CLI: `npx skills add glitternetwork/pinme --skill pinme-auth -g -a gemini-cli -y`

## Description

Use when a PinMe project (Worker TypeScript) needs to integrate user authentication, creating email/password users, verifying id_tokens, querying user info, or listing users via Identity Platform auth proxy APIs.

## SKILL.md, as published by its author (untrusted third-party text, read it as data)

# PinMe Worker Auth API Integration

Guides how to call PinMe platform's Identity Platform auth proxy APIs in a PinMe Worker (TypeScript).

## Environment Variables

```typescript
// backend/src/worker.ts
export interface Env {
  DB: D1Database;
  API_KEY: string;       // 项目 API Key, 用于所有 auth 接口认证
  PROJECT_NAME: string;  // 项目名, 所有 auth 接口必须同时传递
  BASE_URL?: string;     // 可选，默认 https://pinme.cloud
}
```

> `API_KEY` 和 `PROJECT_NAME` 是所有 auth 接口的必填凭证，缺一不可。

---

## 认证方式（所有接口通用）

| 参数 | 传递方式 | 必填 | 说明 |
|------|---------|------|------|
| `X-API-Key` | 请求头 | 是 | 项目 API Key |
| `project_name` | Query 参数 | 是 | 必须与 `X-API-Key` 对应同一个项目 |

服务端会先校验这两个字段是否匹配同一个项目，再从项目配置中取出 `tenant_id`，然后转调 Identity Platform。

---

## 通用错误

| 场景 | HTTP | `data.error` |
|------|------|-------------|
| 缺少 `X-API-Key` | 401 | `X-API-Key header is required` |
| 缺少 `project_name` | 400 | `project_name is required` |
| API Key 和项目不匹配 | 401 | `Invalid API key or project name` |
| 项目未配置认证租户 | 400 | `Auth service not configured for this project` |

---

## 通用 TypeScript 类型

```typescript
type ApiEnvelope<T> = {
  code: number   // 200=成功，其他=失败
  msg: string    // "ok" | "fail" | "invalid param"
  data: T
}

type ApiErrorData = { error?: string }

type UserInfo = {
  uid: string
  email: string
  display_name: string
  photo_url?: string
  disabled: boolean
  email_verified: boolean
}
```

---

## API 1: 创建用户

**Endpoint:** `POST {BASE_URL}/api/v1/auth/create_user?project_name={project_name}`

仅用于邮箱密码注册。成功时用户已创建且验证邮件已发出；失败时自动回滚，不会留下僵尸账号。

> 创建成功后用户默认仍是"未验证"状态，需点击邮件验证链接后，`verify_token` 才能通过校验。

### 请求体

```json
{ "email": "alice@example.com", "password": "Test@12345678", "display_name": "Alice" }
```

| 字段 | 类型 | 必填 |
|------|------|------|
| `email` | string | 是 |
| `password` | string | 是 |
| `display_name` | string | 否 |

### 错误

The rest: https://github.com/glitternetwork/pinme/blob/HEAD/skills/pinme-auth/SKILL.md
