AuthManager is the user authentication management module in NocoBase, used to register different user authentication types.
AuthType: Different user authentication methods, such as password, SMS, OIDC, SAML, etc.Authenticator: The entity for an authentication method, actually stored in a collection, corresponding to a configuration record of a certain AuthType. One authentication method can have multiple authenticators, corresponding to multiple configurations, providing different user authentication methods.Authenticator name: The unique identifier for an authenticator, used to determine the authentication method for the current request.constructor()Constructor, creates an AuthManager instance.
constructor(options: AuthManagerOptions)| Property | Type | Description | Default |
|---|---|---|---|
authKey | string | Optional, the key in the request header that holds the current authenticator identifier. | X-Authenticator |
default | string | Optional, the default authenticator identifier. | basic |
jwt | JwtOptions | Optional, can be configured if using JWT for authentication. | - |
| Property | Type | Description | Default |
|---|---|---|---|
secret | string | Token secret | X-Authenticator |
expiresIn | string | Optional, token expiration time. | 7d |
setStorer()Sets the methods for storing and retrieving authenticator data.
setStorer(storer: Storer)| Property | Type | Description |
|---|---|---|
authType | string | Authentication type |
options | Record<string, any> | Authenticator-related configuration |
Storer is the interface for authenticator storage, containing one method.
get(name: string): Promise<Authenticator> - Gets an authenticator by its identifier. In NocoBase, the actual returned type is AuthModel.registerTypes()Registers an authentication type.
registerTypes(authType: string, authConfig: AuthConfig)| Property | Type | Description |
|---|---|---|
auth | AuthExtend<Auth> | The authentication type implementation, see Auth |
title | string | Optional. The title of this authentication type displayed on the frontend. |
listTypes()Gets the list of registered authentication types.
listTypes(): { name: string; title: string }[]| Property | Type | Description |
|---|---|---|
name | string | Authentication type identifier |
title | string | Authentication type title |
get()Gets an authenticator.
get(name: string, ctx: Context)| Property | Type | Description |
|---|---|---|
name | string | Authenticator identifier |
ctx | Context | Request context |
middleware()Authentication middleware. Gets the current authenticator and performs user authentication.