logologo
Start
Handleiding
Ontwikkeling
Plugins
API
English
简体中文
日本語
한국어
Deutsch
Français
Español
Português
Русский
Italiano
Türkçe
Українська
Tiếng Việt
Bahasa Indonesia
ไทย
Polski
Nederlands
Čeština
العربية
עברית
हिन्दी
Svenska
Start
Handleiding
Ontwikkeling
Plugins
API
logologo
API-overzicht

@nocobase/auth

AuthManager
Auth
BaseAuth

@nocobase/cache

CacheManager
Cache

@nocobase/cli

NocoBase CLI
Globale Omgevingsvariabelen

@nocobase/client

Applicatie
Plugin

@nocobase/database

Collectie
Veld

interfaces

BaseInterface
Filteroperatoren

RelationRepository

BelongsToManyRepository
belongs-to-repository
HasManyRepository
HasOneRepository
Repository

shared

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

@nocobase/data-source-manager

DataSourceManager
DataSource (abstract)
ICollectionManager
ICollection
IField
IModel
IRepository

@nocobase/flow-engine

Gegevensbronbeheerder
FlowContext
FlowEngine
FlowModel
Workflowbron

@nocobase/logger

Logger

@nocobase/server

AppCommand
Applicatie
AuditManager
Context
Migratie
Plugin

@nocobase/sdk

Auth
Storage
Previous PageAPI-overzicht
Next PageAuth
TIP

Dit document is vertaald door AI. Voor onnauwkeurigheden, raadpleeg de Engelse versie

#AuthManager

#Overzicht

AuthManager is de module voor gebruikersauthenticatiebeheer in NocoBase. U gebruikt deze om verschillende typen gebruikersauthenticatie te registreren.

#Basisgebruik

const authManager = new AuthManager({
  // Wordt gebruikt om de huidige authenticator-ID uit de request header te halen
  authKey: 'X-Authenticator',
});

// Stel de methoden in voor AuthManager om authenticators op te slaan en op te halen
authManager.setStorer({
  get: async (name: string) => {
    return db.getRepository('authenticators').find({ filter: { name } });
  },
});

// Registreer een authenticatietype
authManager.registerTypes('basic', {
  auth: BasicAuth,
  title: 'Password',
});

// Gebruik de authenticatie-middleware
app.resourceManager.use(authManager.middleware());

#Concepten

  • Authenticatietype (AuthType): Verschillende methoden voor gebruikersauthenticatie, zoals wachtwoord, sms, OIDC, SAML, enz.
  • Authenticator (Authenticator): De entiteit voor een authenticatiemethode, die daadwerkelijk wordt opgeslagen in een collectie. Deze komt overeen met een configuratierecord van een bepaald AuthType. Eén authenticatiemethode kan meerdere authenticators hebben, die overeenkomen met meerdere configuraties en verschillende methoden voor gebruikersauthenticatie bieden.
  • Authenticator-ID (Authenticator name): De unieke identificatie voor een authenticator, gebruikt om de authenticatiemethode voor het huidige verzoek te bepalen.

#Klasse-methoden

#constructor()

Constructor, creëert een AuthManager-instantie.

#Handtekening

  • constructor(options: AuthManagerOptions)

#Typen

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

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

#Details

#AuthManagerOptions
EigenschapTypeBeschrijvingStandaardwaarde
authKeystringOptioneel, de sleutel in de request header die de ID van de huidige authenticator bevat.X-Authenticator
defaultstringOptioneel, de standaard authenticator-ID.basic
jwtJwtOptionsOptioneel, kan worden geconfigureerd als u JWT gebruikt voor authenticatie.-
#JwtOptions
EigenschapTypeBeschrijvingStandaardwaarde
secretstringToken-geheimX-Authenticator
expiresInstringOptioneel, de geldigheidsduur van het token.7d

#setStorer()

Stelt de methoden in voor het opslaan en ophalen van authenticator-gegevens.

#Handtekening

  • setStorer(storer: Storer)

#Typen

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

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

#Details

#Authenticator
EigenschapTypeBeschrijving
authTypestringAuthenticatietype
optionsRecord<string, any>Authenticator-gerelateerde configuratie
#Storer

Storer is de interface voor authenticator-opslag, en bevat één methode.

  • get(name: string): Promise<Authenticator> - Haalt een authenticator op via de ID. In NocoBase is het daadwerkelijk geretourneerde type AuthModel.

#registerTypes()

Registreert een authenticatietype.

#Handtekening

  • registerTypes(authType: string, authConfig: AuthConfig)

#Typen

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.
};

#Details

EigenschapTypeBeschrijving
authAuthExtend<Auth>De implementatie van het authenticatietype, zie Auth
titlestringOptioneel. De titel van dit authenticatietype zoals weergegeven in de frontend.

#listTypes()

Haalt de lijst met geregistreerde authenticatietypen op.

#Handtekening

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

#Details

EigenschapTypeBeschrijving
namestringAuthenticatietype-ID
titlestringTitel van het authenticatietype

#get()

Haalt een authenticator op.

#Handtekening

  • get(name: string, ctx: Context)

#Details

EigenschapTypeBeschrijving
namestringAuthenticator-ID
ctxContextRequest context

#middleware()

Authenticatie-middleware. Haalt de huidige authenticator op en voert gebruikersauthenticatie uit.