logologo
เริ่มต้น
คู่มือ
การพัฒนา
ปลั๊กอิน
API
English
简体中文
日本語
한국어
Deutsch
Français
Español
Português
Русский
Italiano
Türkçe
Українська
Tiếng Việt
Bahasa Indonesia
ไทย
Polski
Nederlands
Čeština
العربية
עברית
हिन्दी
Svenska
เริ่มต้น
คู่มือ
การพัฒนา
ปลั๊กอิน
API
logologo
API Overview

@nocobase/auth

AuthManager
Auth
BaseAuth

@nocobase/cache

CacheManager
แคช

@nocobase/cli

NocoBase CLI
ตัวแปรสภาพแวดล้อมส่วนกลาง

@nocobase/client

แอปพลิเคชัน
ปลั๊กอิน

@nocobase/database

คอลเลกชัน
ฟิลด์

interfaces

BaseInterface
ตัวดำเนินการ Filter

RelationRepository

BelongsToManyRepository
belongs-to-repository
HasManyRepository
HasOneRepository
รีโพสิทอรี

shared

create-options
destroy-options
find-one
find-options
transaction
update-options

@nocobase/data-source-manager

DataSourceManager
แหล่งข้อมูล (abstract)
ICollectionManager
ICollection
IField
IModel
IRepository

@nocobase/flow-engine

ตัวจัดการแหล่งข้อมูล
โฟลว์บริบท
FlowEngine
FlowModel
ทรัพยากรเวิร์กโฟลว์

@nocobase/logger

Logger

@nocobase/server

AppCommand
แอปพลิเคชัน
AuditManager
บริบท
การไมเกรต
ปลั๊กอิน

@nocobase/sdk

Auth
สตอเรจ
Previous PageAPI Overview
Next PageAuth
TIP

เอกสารนี้แปลโดย AI หากมีข้อมูลที่ไม่ถูกต้อง โปรดดูเวอร์ชันภาษาอังกฤษ

#AuthManager

#ภาพรวม

AuthManager เป็นโมดูลจัดการการยืนยันตัวตนผู้ใช้ใน NocoBase ครับ/ค่ะ ใช้สำหรับลงทะเบียนประเภทการยืนยันตัวตนผู้ใช้ที่แตกต่างกัน

#การใช้งานเบื้องต้น

const authManager = new AuthManager({
  // ใช้สำหรับดึงตัวระบุ Authenticator ปัจจุบันจาก Header ของ Request
  authKey: 'X-Authenticator',
});

// กำหนดวิธีการจัดเก็บและดึง Authenticator ของ AuthManager
authManager.setStorer({
  get: async (name: string) => {
    return db.getRepository('authenticators').find({ filter: { name } });
  },
});

// ลงทะเบียนประเภทการยืนยันตัวตน
authManager.registerTypes('basic', {
  auth: BasicAuth,
  title: 'Password',
});

// ใช้ Middleware สำหรับการยืนยันตัวตน
app.resourceManager.use(authManager.middleware());

#คำอธิบายแนวคิด

  • ประเภทการยืนยันตัวตน (AuthType): วิธีการยืนยันตัวตนผู้ใช้ที่แตกต่างกัน เช่น รหัสผ่าน, SMS, OIDC, SAML เป็นต้น
  • Authenticator: เอนทิตีสำหรับวิธีการยืนยันตัวตน ซึ่งจะถูกจัดเก็บจริงในคอลเลกชัน โดยจะสอดคล้องกับบันทึกการกำหนดค่าของ AuthType บางประเภท วิธีการยืนยันตัวตนหนึ่งวิธีสามารถมี Authenticator ได้หลายตัว ซึ่งจะสอดคล้องกับการกำหนดค่าหลายชุด และมีวิธีการยืนยันตัวตนผู้ใช้ที่แตกต่างกัน
  • ตัวระบุ Authenticator (Authenticator name): ตัวระบุเฉพาะสำหรับ Authenticator ใช้เพื่อระบุวิธีการยืนยันตัวตนที่ใช้สำหรับ Request ปัจจุบัน

#เมธอดของคลาส

#constructor()

Constructor ใช้สำหรับสร้างอินสแตนซ์ของ AuthManager ครับ/ค่ะ

#Signature

  • constructor(options: AuthManagerOptions)

#Types

export interface JwtOptions {
  secret: string;
  expiresIn?: string;
}

export type AuthManagerOptions = {
  authKey: string;
  default?: string;
  jwt?: JwtOptions;
};

#รายละเอียด

#AuthManagerOptions
คุณสมบัติประเภทคำอธิบายค่าเริ่มต้น
authKeystringไม่บังคับ, คีย์ใน Header ของ Request ที่ใช้เก็บตัวระบุ Authenticator ปัจจุบันX-Authenticator
defaultstringไม่บังคับ, ตัวระบุ Authenticator เริ่มต้นbasic
jwtJwtOptionsไม่บังคับ, สามารถกำหนดค่าได้หากใช้ JWT ในการยืนยันตัวตน-
#JwtOptions
คุณสมบัติประเภทคำอธิบายค่าเริ่มต้น
secretstringคีย์ลับของ TokenX-Authenticator
expiresInstringไม่บังคับ, ระยะเวลาหมดอายุของ Token7d

#setStorer()

กำหนดวิธีการจัดเก็บและดึงข้อมูล Authenticator ครับ/ค่ะ

#Signature

  • setStorer(storer: Storer)

#Types

export interface Authenticator = {
  authType: string;
  options: Record<string, any>;
  [key: string]: any;
};

export interface Storer {
  get: (name: string) => Promise<Authenticator>;
}

#รายละเอียด

#Authenticator
คุณสมบัติประเภทคำอธิบาย
authTypestringประเภทการยืนยันตัวตน
optionsRecord<string, any>การกำหนดค่าที่เกี่ยวข้องกับ Authenticator
#Storer

Storer คืออินเทอร์เฟซสำหรับการจัดเก็บ Authenticator ซึ่งมีหนึ่งเมธอดครับ/ค่ะ

  • get(name: string): Promise<Authenticator) - ดึง Authenticator โดยใช้ตัวระบุ Authenticator ใน NocoBase ประเภทที่ส่งคืนจริงคือ AuthModel ครับ/ค่ะ

#registerTypes()

ลงทะเบียนประเภทการยืนยันตัวตนครับ/ค่ะ

#Signature

  • registerTypes(authType: string, authConfig: AuthConfig)

#Types

export type AuthExtend<T extends Auth> = new (config: Config) => T;

type AuthConfig = {
  auth: AuthExtend<Auth>; // The authentication class.
  title?: string; // The display name of the authentication type.
};

#รายละเอียด

คุณสมบัติประเภทคำอธิบาย
authAuthExtend<Auth>การนำประเภทการยืนยันตัวตนไปใช้งาน, ดู Auth
titlestringไม่บังคับ, ชื่อเรื่องของประเภทการยืนยันตัวตนนี้ที่จะแสดงผลบนส่วนหน้า (Frontend)

#listTypes()

ดึงรายการประเภทการยืนยันตัวตนที่ลงทะเบียนไว้ครับ/ค่ะ

#Signature

  • listTypes(): { name: string; title: string }[]

#รายละเอียด

คุณสมบัติประเภทคำอธิบาย
namestringตัวระบุประเภทการยืนยันตัวตน
titlestringชื่อเรื่องของประเภทการยืนยันตัวตน

#get()

ดึง Authenticator ครับ/ค่ะ

#Signature

  • get(name: string, ctx: Context)

#รายละเอียด

คุณสมบัติประเภทคำอธิบาย
namestringตัวระบุ Authenticator
ctxContextบริบทของ Request

#middleware()

Middleware สำหรับการยืนยันตัวตนครับ/ค่ะ ใช้สำหรับดึง Authenticator ปัจจุบันและดำเนินการยืนยันตัวตนผู้ใช้