Auth Center

raw JSON →
2.2.0 verified Sat Apr 25 auth: no javascript

Auth Center is an OAuth2.0 authorization server with TOTP (Time-based One-Time Password) support for Node.js. Version 2.2.0 (stable) includes built-in admin UI, supports MySQL, PostgreSQL, SQLite, and MariaDB via Sequelize ORM, and provides both CLI and programmatic interfaces. It implements the OAuth2.0 authorization code grant flow and enhances password authentication with TOTP. Compared to alternatives like oauth2orize, it offers an all-in-one solution with session management (Redis support), email integration, and database schema synchronization.

error Error: Cannot find module 'auth-center'
cause Package not installed or incorrect install path.
fix
Run 'npm install auth-center --save' in project root.
error SequelizeConnectionError: Unknown database 'db_auth'
cause Database does not exist or config uses wrong dialect.
fix
Create the database manually or set orm.dialect to 'sqlite' for file-based storage.
error TypeError: AuthServer is not a constructor
cause Using 'new AuthServer()' instead of calling AuthServer() as a function.
fix
Use 'const server = AuthServer(config);' without 'new'.
breaking Removed support for Node.js < 8. Engines field requires node >= 8.
fix Upgrade Node.js to version 8 or higher.
deprecated Using force: true on sync will drop existing tables. Use with caution in production.
fix Use alter: true or migrate manually instead of force.
gotcha OAuth2.0 only supports authorization code grant type; implicit and client credentials are not implemented.
fix Use authorization code flow or extend the library.
gotcha Session secret must be provided via config, otherwise default is insecure.
fix Always set session.secret in config.
breaking Database dialect 'postgres' renamed to 'postgres' (case-sensitive).
fix Use 'postgres' (lowercase) in orm.dialect.
npm install auth-center
yarn add auth-center
pnpm add auth-center

Initializes an Auth Center server with SQLite, syncs database schema, and listens on port 3000.

const AuthServer = require('auth-center');

const server = AuthServer({
  domain: 'http://localhost:3000',
  orm: {
    database: 'db_auth',
    username: 'root',
    password: process.env.DB_PASSWORD ?? '',
    dialect: 'sqlite',
    storage: './auth.db'
  },
  session: {
    secret: 'my-secret-key'
  },
  mail: {
    from: 'admin@example.com',
    host: 'smtp.example.com',
    port: 465,
    secure: true,
    auth: {
      user: 'user',
      pass: 'pass'
    }
  }
});

server.listen(3000, () => {
  console.log('Auth Center running on http://localhost:3000');
  server.orm.database().sync({ force: true }).then(() => console.log('Sync done.'));
});