Scripts2026年4月10日·1 分钟阅读

Logto — Open Source Authentication & Authorization for SaaS

Logto is an open-source Auth0 alternative providing OIDC/OAuth 2.1 authentication with multi-tenancy, SSO, RBAC, and MFA for modern SaaS and AI apps.

SC
Script Depot · Community
快速使用

先拿来用,再决定要不要深挖

这里应该同时让用户和 Agent 知道第一步该复制什么、安装什么、落到哪里。

docker run --name logto -p 3001:3001 -p 3002:3002 
  -e DB_URL=postgres://postgres:password@host.docker.internal:5432/logto 
  ghcr.io/logto-io/logto:latest

Open http://localhost:3002 (Admin Console) — set up your first application and sign-in experience.

介绍

Logto is an open-source authentication and authorization platform built on OIDC and OAuth 2.1 standards. It provides a complete identity infrastructure for SaaS applications with multi-tenancy, social login, SSO, MFA, and role-based access control out of the box.

With 11.9K+ GitHub stars and MPL-2.0 license, Logto offers both self-hosted and cloud options, making it a viable alternative to Auth0, Clerk, and Firebase Auth with full data ownership.

What Logto Does

Logto handles the entire authentication and authorization lifecycle:

  • Sign-in Experience: Customizable login pages with email/password, phone OTP, social login (Google, GitHub, Apple, etc.), and passwordless options
  • Multi-tenancy: Organizations with member management, invitation flows, and per-org settings
  • Single Sign-On (SSO): Enterprise SSO with SAML and OIDC federation for connecting corporate identity providers
  • Access Control: Role-based access control (RBAC) with API resource permissions and organization-level roles
  • Multi-factor Authentication: TOTP authenticator apps, WebAuthn/passkeys, and backup codes

Architecture

┌──────────────┐     ┌──────────────┐     ┌──────────────┐
│  Your App    │────▶│  Logto Core  │────▶│  PostgreSQL  │
│  (SDK)       │     │  (OIDC/OAuth)│     │  (Users/Orgs)│
└──────────────┘     └──────┬───────┘     └──────────────┘
                            │
                     ┌──────┴───────┐
                     │ Admin Console│
                     │  (React SPA) │
                     └──────────────┘

Integration Example (Next.js)

npm install @logto/next
// app/api/logto/[action]/route.ts
import { handleSignIn, handleSignOut, handleCallback } from '@logto/next/server-actions';
import { logtoConfig } from './config';

export { handleSignIn, handleSignOut, handleCallback };

// logto.config.ts
export const logtoConfig = {
  endpoint: 'http://localhost:3001',
  appId: 'your-app-id',
  appSecret: 'your-app-secret',
  baseUrl: 'http://localhost:3000',
  cookieSecret: 'your-cookie-secret',
  cookieSecure: process.env.NODE_ENV === 'production',
};
// app/page.tsx
import { getLogtoContext } from '@logto/next/server-actions';

export default async function Home() {
  const { isAuthenticated, claims } = await getLogtoContext(logtoConfig);

  return isAuthenticated ? (
    <div>Welcome, {claims?.name}</div>
  ) : (
    <a href="/api/logto/sign-in">Sign In</a>
  );
}

SDKs Available

Logto provides official SDKs for all major platforms:

Platform Package
React @logto/react
Next.js @logto/next
Vue @logto/vue
Express @logto/express
Python (Flask/Django) logto
Go github.com/logto-io/go
iOS/Android Native SDKs

Self-Hosting

Docker Compose

services:
  logto:
    image: ghcr.io/logto-io/logto:latest
    ports:
      - "3001:3001"  # Core API
      - "3002:3002"  # Admin Console
    environment:
      DB_URL: postgres://logto:logto@postgres:5432/logto
      ENDPOINT: http://localhost:3001
      ADMIN_ENDPOINT: http://localhost:3002
    depends_on:
      - postgres

  postgres:
    image: postgres:16
    environment:
      POSTGRES_USER: logto
      POSTGRES_PASSWORD: logto
      POSTGRES_DB: logto
    volumes:
      - pg-data:/var/lib/postgresql/data

volumes:
  pg-data:

Logto vs Alternatives

Feature Logto Auth0 Clerk Firebase Auth
Open Source Yes (MPL-2.0) No No No
Self-hosted Yes No No No
Multi-tenancy Built-in Enterprise No No
SSO (SAML/OIDC) Yes Enterprise Enterprise No
MFA TOTP + Passkeys Yes Yes Phone only
Pricing Free (self-host) Free tier + paid Per MAU Free tier + paid

常见问题

Q: Logto 能处理多大规模的用户? A: 自托管 Logto 基于 PostgreSQL,轻松处理百万级用户。Cloud 版本使用分布式架构支持更大规模。

Q: 已经用了 Auth0,迁移到 Logto 难吗? A: Logto 遵循 OIDC 标准,提供用户导入 API 和兼容的 SDK 接口。大多数应用只需更换 SDK 和配置即可迁移。

Q: 支持 Machine-to-Machine (M2M) 认证吗? A: 支持。Logto 提供 client_credentials grant 用于服务间认证,适合微服务和 API 网关场景。

来源与致谢

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产