logologo
Get Started
Guide
Development
Plugins
API
English
简体中文
Get Started
Guide
Development
Plugins
API
English
简体中文
logologo

Authentication

Overview
Authenticators

Authentication type

Password
SMS

OIDC

Configuration

Examples

Google
Microsoft Entra ID

SAML

Configuration

Examples

Google Workspace
LDAP
CAS
API keys

Development

Extentd authentication type
API

Verification

Overview

Verification type

SMS
TOTP authenticator

Development

Extend verification type
Extend verification scene
Extend SMS provider
API
Two factor authentication (2FA)
Previous PageExtentd authentication type
Next PageOverview

#API Reference

#Server Side

#Auth

Kernel API, reference: Auth

#BaseAuth

Kernel API, reference: BaseAuth

#AuthModel

#Overview

AuthModel is the authenticator used in NocoBase applications (Authenticator, reference: AuthManager - setStorer and Auth - constructor) data model, providing some methods for interacting with the user data collection. In addition, methods provided by Sequelize Model can also be used.

import { AuthModel } from '@nocobase/plugin-auth';

class CustomAuth extends BaseAuth {
  async validate() {
    // ...
    const authenticator = this.authenticator as AuthModel;
    this.authenticator.findUser();
    this.authenticator.newUser();
    this.authenticator.findOrCreateUser();
    // ...
  }
}

#Class Methods

  • findUser(uuid: string): UserModel - Query user by uuid.

    • uuid - User unique identifier from the current authentication type
  • newUser(uuid: string, userValues?: any): UserModel - Create a new user, bind the user to the current authenticator through uuid.

    • uuid - User unique identifier from the current authentication type
    • userValues - Optional. Other user information. When not passed, uuid will be used as the user's nickname.
  • findOrCreateUser(uuid: string, userValues?: any): UserModel - Find or create a new user, the creation rule is the same as above.

    • uuid - User unique identifier from the current authentication type
    • userValues - Optional. Other user information.

#Client Side

#plugin.registerType()

Register the client of the authentication type.

import AuthPlugin from '@nocobase/plugin-auth/client';

class CustomAuthPlugin extends Plugin {
  async load() {
    const auth = this.app.pm.get(AuthPlugin);
    auth.registerType('custom-auth-type', {
      components: {
        SignInForm,
        // SignInButton
        SignUpForm,
        AdminSettingsForm,
      },
    });
  }
}

#Signature

  • registerType(authType: string, options: AuthOptions)

#Type

export type AuthOptions = {
  components: Partial<{
    SignInForm: ComponentType<{ authenticator: AuthenticatorType }>;
    SignInButton: ComponentType<{ authenticator: AuthenticatorType }>;
    SignUpForm: ComponentType<{ authenticatorName: string }>;
    AdminSettingsForm: ComponentType;
  }>;
};

#Details

  • SignInForm - Sign in form
  • SignInButton - Sign in (third-party) button, can be used as an alternative to the sign-in form
  • SignUpForm - Sign up form
  • AdminSettingsForm - Admin configuration form

#Route

The frontend routes for registering the auth plugin are as follows:

  • Auth Layout

    • name: auth
    • path: -
    • component: AuthLayout
  • SignIn Page

    • name: auth.signin
    • path: /signin
    • component: SignInPage
  • SignUp Page

    • name: auth.signup
    • path: /signup
    • component: SignUpPage