
ไลบรารีสำหรับยืนยันตัวตนที่ครบถ้วนและต่อเติมได้ทุกชิ้นส่วน รองรับ 4 รูปแบบการเข้าสู่ระบบ มีการจัดเก็บและรีเฟรชโทเค็น ล็อกข้ามโปรเซส ต่อ keychain ได้ ทุกส่วนจัดการให้และเปลี่ยนได้
npm install cli-authเลือกกลยุทธ์ ระบบพื้นฐานจัดการให้ครบ
รูปแบบที่เหมาะกับ server, shell ใน Docker หรือเครื่องไหนที่เปิด browser ไม่ได้
1import { createCliAuth, keyringStorage } from 'cli-auth';2import { Entry } from '@napi-rs/keyring';3 4const auth = createCliAuth({5 strategy: 'device-code',6 provider: {7 metadata: {8 deviceAuthorizationEndpoint: 'https://your-tenant.logto.app/oidc/device/auth',9 tokenEndpoint: 'https://your-tenant.logto.app/oidc/token',10 },11 },12 clientId: 'your-cli-client',13 storage: keyringStorage({ entry: new Entry('your-cli', 'tokens') }),14 scope: 'openid offline_access',15});16 17await auth.login({18 onAuthorization: ({ userCode, verificationUri }) => {19 console.log(`Visit ${verificationUri} and enter ${userCode}`);20 },21});22 23const accessToken = await auth.getToken();แต่ละข้อคือบั๊ก เงื่อนไข หรือข้อกำหนดที่เราจัดการให้หมดแล้ว

storage, locking, fetch, หน้า callback เป็น hook ทั้งหมด ไม่มี hardcode คุณคลิกเลือกได้แล้วตัว config จะเปลี่ยนตาม
ที่เก็บ1import { createCliAuth } from 'cli-auth';2 3const auth = createCliAuth({4 strategy: 'authorization-code',5 provider: { /* ... */ },6 clientId: 'your-cli-client',7 storage: keyringStorage({ entry: new Entry('your-cli', 'tokens') }),8});OAuth 2.0 หรือ OIDC อะไรก็ได้ ชี้ endpoint ไลบรารีทำงานทันที ไม่ได้สร้างมาใช้กับ Logto เท่านั้น
ยืนยันตัวตนบน CLI โดยไม่ต้องเสียเวลาเขียนเอง