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概要

@nocobase/auth

AuthManager
Auth
BaseAuth

@nocobase/cache

CacheManager
キャッシュ

@nocobase/cli

NocoBase CLI
グローバル環境変数

@nocobase/client

アプリケーション
プラグイン

@nocobase/database

コレクション
フィールド

interfaces

BaseInterface
フィルター演算子

RelationRepository

BelongsToManyRepository
belongs-to-repository
HasManyRepository
HasOneRepository
リポジトリ

shared

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

@nocobase/data-source-manager

DataSourceManager
DataSource (抽象)
ICollectionManager
ICollection
IField
IModel
IRepository

@nocobase/flow-engine

データソースマネージャー
フローコンテキスト
FlowEngine
フローモデル
フローリソース

@nocobase/logger

ロガー

@nocobase/server

AppCommand
アプリケーション
AuditManager
コンテキスト
マイグレーション
プラグイン

@nocobase/sdk

Auth
ストレージ
Previous PageAPI概要
Next PageAuth
TIP

このドキュメントはAIによって翻訳されました。不正確な情報については、英語版をご参照ください

#AuthManager

#概要

AuthManager は NocoBase のユーザー認証管理モジュールで、様々なユーザー認証タイプを登録するために使用されます。

#基本的な使い方

const authManager = new AuthManager({
  // リクエストヘッダーから現在の認証器識別子を取得するために使用されます
  authKey: 'X-Authenticator',
});

// AuthManager が認証器を保存・取得するためのメソッドを設定します
authManager.setStorer({
  get: async (name: string) => {
    return db.getRepository('authenticators').find({ filter: { name } });
  },
});

// 認証タイプを登録します
authManager.registerTypes('basic', {
  auth: BasicAuth,
  title: 'Password',
});

// 認証ミドルウェアを使用します
app.resourceManager.use(authManager.middleware());

#概念

  • 認証タイプ (AuthType): パスワード、SMS、OIDC、SAML など、様々なユーザー認証方法です。
  • 認証器 (Authenticator): 認証方式の実体で、実際にデータテーブルに保存され、特定の認証タイプ (AuthType) の設定レコードに対応します。一つの認証方式で複数の認証器を持つことができ、それぞれが複数の設定に対応し、様々なユーザー認証方法を提供します。
  • 認証器識別子 (Authenticator name): 認証器の一意な識別子で、現在のリクエストで使用される認証方式を特定するために使用されます。

#クラスメソッド

#constructor()

コンストラクタで、AuthManager のインスタンスを作成します。

#シグネチャ

  • constructor(options: AuthManagerOptions)

#型

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

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

#詳細

#AuthManagerOptions
プロパティ型説明デフォルト値
authKeystringオプション。リクエストヘッダーで現在の認証器識別子を保持するキーです。X-Authenticator
defaultstringオプション。デフォルトの認証器識別子です。basic
jwtJwtOptionsオプション。JWT を使用して認証を行う場合に設定できます。-
#JwtOptions
プロパティ型説明デフォルト値
secretstringトークンの秘密鍵X-Authenticator
expiresInstringオプション。トークンの有効期限です。7d

#setStorer()

認証器データの保存および取得方法を設定します。

#シグネチャ

  • setStorer(storer: Storer)

#型

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>認証器関連の設定
#Storer

Storer は認証器のストレージインターフェースで、一つのメソッドを含みます。

  • get(name: string): Promise<Authenticator> - 認証器識別子を使って認証器を取得します。NocoBase では、実際に返される型は AuthModel です。

#registerTypes()

認証タイプを登録します。

#シグネチャ

  • registerTypes(authType: string, authConfig: AuthConfig)

#型

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オプション。この認証タイプがフロントエンドで表示されるタイトルです。

#listTypes()

登録済みの認証タイプリストを取得します。

#シグネチャ

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

#詳細

プロパティ型説明
namestring認証タイプ識別子
titlestring認証タイプタイトル

#get()

認証器を取得します。

#シグネチャ

  • get(name: string, ctx: Context)

#詳細

プロパティ型説明
namestring認証器識別子
ctxContextリクエストコンテキスト

#middleware()

認証ミドルウェアです。現在の認証器を取得し、ユーザー認証を行います。