关于 auth0-cli
auth0-cli 是用于在命令行管理 Auth0 租户的工具,面向开发者和运维人员。它涵盖应用、用户、访问控制、监控及配置导出,并提供便于脚本处理的机器可读输出。
主要功能
- 01管理应用、API 和用户
- 02配置角色与组织
- 03创建并部署身份验证 Actions
- 04查看并转发租户日志
- 05将配置导出为 Terraform
- 06使用 JSON 和 CSV 输出
适用场景
- 01设置 Auth0 应用和 API
- 02搜索用户或批量导入用户
- 03通过租户日志排查登录失败
- 04为租户生成 Terraform 配置
安装
复制下面的命令,在终端中运行。
npx skills add https:/ / github.com/ auth0/ agent-skills --skill auth0-cli安装后在 Claude Code 中输入/auth0-cli确认已加载。
附带文件references/cli.mdtests/evals.json
详细介绍
Auth0 CLI — 命令参考
Auth0 CLI(auth0)让你可以在终端中管理租户。通过 Homebrew 安装(brew install auth0/auth0-cli/auth0)。有关完整的标志定义和示例,请参阅完整 CLI 参考。
开始之前:进行身份验证
auth0 login # interactive device-code login
auth0 login --scopes "read:client_grants" # request extra scopes if 403
auth0 login --domain <tenant>.auth0.com --client-id <id> --client-secret "$AUTH0_CLIENT_SECRET" # CI/CD
有关使用 JWT 进行机器登录、租户管理和注销,请参阅身份验证详情。
快速决策指南
| 要执行的操作 | 使用的命令 |
|---|---|
| 设置新项目 | auth0 apps create --type spa|regular|m2m|native --json |
| 需要客户端 ID 或密钥 | auth0 apps show <id> -r --json |
| 注册后端 API | auth0 apis create --identifier "https://..." --json |
| 查找用户 ID | auth0 users search --query "email:..." --json |
| 创建/管理角色(RBAC) | auth0 roles create / auth0 users roles assign |
| B2B 多租户 | auth0 orgs create |
| 自定义登录逻辑 | auth0 actions create --trigger post-login --json |
| 设置登录页面品牌样式 | auth0 ul update --logo ... --accent ... |
| 登录自定义域名 | auth0 domains create --domain "auth.myapp.com" --json |
| 调试失败的登录 | auth0 logs tail --filter "type:f" --json-compact |
| 测试登录流程 | auth0 test login <client-id> |
| 将配置导出为 Terraform | auth0 terraform generate --output-dir ./terraform |
| 管理连接、授权和钩子 | auth0 api get <path> |
| 编写脚本/解析输出 | 在任意命令中添加 --json 或 --json-compact |
| 加强安全性 | auth0 protection brute-force-protection update --enabled true |
| 将日志路由到外部 | auth0 logs streams create datadog|http|splunk |
| 批量导入用户 | auth0 users import --connection-name ... --users '...' --json |
命令概览
Apps — 管理应用程序
创建或查看 Auth0 应用程序(客户端 ID、密钥、回调 URL、应用程序类型)。别名:auth0 clients。
auth0 apps create --name "My SPA" --type spa \
--auth-method None \
--callbacks "http://localhost:3000" \
--logout-urls "http://localhost:3000" \
--origins "http://localhost:3000" --json
auth0 apps list --json-compact
auth0 apps show <client-id> --json
auth0 apps update <client-id> --callbacks "http://localhost:3000,https://myapp.com" --json
auth0 apps delete <client-id> --force
应用程序类型:spa、regular、m2m、native、resource_server
完整详情:Apps 参考
APIs — 管理 API 资源
注册要使用 Auth0 令牌保护的后端 API(资源服务器)。别名:auth0 resource-servers。
auth0 apis create --name "My API" --identifier "https://api.myapp.com" \
--scopes "read:data,write:data" --token-lifetime 3600 --json
auth0 apis list --json-compact
auth0 apis scopes list <api-id> --json
关键区别:apps = 请求令牌的客户端。apis = 接受令牌的资源。
完整详情:APIs 参考
Users — 管理用户
在租户中创建、搜索、查看、导入和管理用户。
auth0 users search --query "email:[email protected]" --json
auth0 users search-by-email [email protected] --json-compact
auth0 users create --connection-name "Username-Password-Authentication" \
--email "[email protected]" --password "$USER_PASSWORD" --json
auth0 users show <user-id> --json
auth0 users blocks list <email> --json
auth0 users blocks unblock <email>
auth0 users import --connection-name "Username-Password-Authentication" \
--users '[...]' --upsert --json
完整详情:Users 参考
Roles — 管理 RBAC 角色
创建角色、分配权限,并为用户分配角色。CLI 为所有角色操作提供了专用命令。
auth0 roles create --name "editor" --description "Can edit content" --json
auth0 roles permissions add <role-id> --api-id <api-id> --permissions "read:data,write:data" --json
auth0 users roles assign <user-id> --roles <role-id>
auth0 users roles show <user-id> --json-compact
完整详情:Roles 参考
Organizations — B2B 多租户
管理适用于 B2B SaaS 场景的组织。别名:auth0 orgs。
auth0 orgs create --name "acme-corp" --display "Acme Corporation" \
--logo "https://acme.com/logo.png" --accent "#FF6600" --json
auth0 orgs members list <org-id> --json
auth0 orgs invitations create --org-id <org-id> --invitee-email "[email protected]" \
--inviter-name "Admin" --client-id <id> --json
完整详情:Organizations 参考
Actions — 无服务器身份验证管道
在身份验证管道的触发点创建并部署无服务器函数。用于替代已弃用的 Rules。
auth0 actions create --name "Add Claims" --trigger "post-login" \
--code 'exports.onExecutePostLogin = async (event, api) => { ... }' --json
auth0 actions deploy <action-id>
触发器:post-login、credentials-exchange、pre-user-registration、post-user-registration、post-change-password、send-phone-message
**重要:**创建或更新后,必须执行 deploy,更改才会生效。
完整详情:Actions 参考
Logs — 调试与监控
auth0 logs tail --filter "type:f" --json-compact # real-time failed logins
auth0 logs list --filter "type:f" --number 20 --json-compact # historical
常见代码:s(成功)、f(登录失败)、slo(注销)、fs(静默身份验证失败)
完整详情:Logs 参考
Domains — 自定义域名
auth0 domains create --domain "auth.myapp.com" --type "auth0_managed_certs" --json
auth0 domains verify <domain-id> --json
完整详情:Domains 参考
Universal Login — 品牌样式
auth0 ul update --accent "#FF6600" --background "#FFFFFF" \
--logo "https://myapp.com/logo.png" --json
完整详情:Universal Login 参考
Terraform — 导出为 IaC
auth0 terraform generate --output-dir ./terraform --resources "auth0_client,auth0_connection"
完整详情:Terraform 参考
测试 — 验证登录流程
auth0 test login <client-id>
auth0 test login <client-id> --audience "https://api.myapp.com" --scopes "openid profile email"
详情:测试参考
攻击防护 — 安全加固
auth0 protection brute-force-protection update --enabled true
auth0 protection breached-password-detection update --enabled true
auth0 protection bot-detection update --enabled true
详情:攻击防护参考
日志流 — 外部路由
auth0 logs streams create datadog # interactive setup
auth0 logs streams create http # custom webhook
auth0 logs streams list --json
支持:eventbridge、eventgrid、http、datadog、splunk、sumo
详情:日志流参考
原始 API 模式 — 直接访问管理 API
当没有专用命令时,auth0 api 会直接调用 Management API v2 端点。
auth0 api get connections
auth0 api post client-grants --data '{"client_id":"...","audience":"...","scope":["read:data"]}'
auth0 api get stats/daily -q "from=20240101" -q "to=20240131"
详情:原始 API 参考
输出格式
始终使用 --json 或 --json-compact 生成机器可读的输出。共有三种模式(互斥):
| 标志 | 使用场景 |
|---|---|
--json | 人工查看、调试 — 以缩进格式美化输出 |
--json-compact | 管道传递给 jq、脚本、流水线 — 压缩为单行 |
--csv | 电子表格和表格数据导出 |
auth0 apps list --json-compact | jq '.[] | {client_id, name}'
auth0 users show <user-id> --json-compact | jq '{id: .user_id, email: .email}'
auth0 roles list --json-compact | jq '.[].name'
详情:输出格式参考
参考文档
完整的 CLI 参考文档,包含所有标志、示例和用法模式:
- 设置指南 — 安装、身份验证、CI/CD 配置
- 身份验证 — 登录模式、租户管理、作用域
- 应用 — 创建、列出、查看、更新、删除、会话转移
- API — 创建、作用域、令牌生命周期
- 用户 — 搜索、创建、导入、封禁、角色
- 角色 — RBAC 设置、权限管理
- 组织 — B2B、成员、邀请
- Actions — 流水线触发器、部署工作流
- 日志 — 实时查看、列出、类型代码
- 域名 — 自定义域名、验证
- Universal Login — 品牌、模板、提示词
- Terraform — IaC 导出
- 测试 — 登录流程验证
- 攻击防护 — 暴力破解、泄露、机器人检测
- 日志流 — 外部服务路由
- 原始 API 模式 — 直接访问 Management API
- 输出格式 — --json、--json-compact、--csv
- 共享标志 — --tenant、--no-input、--debug
相关技能
auth0-quickstart— Auth0 初始设置、框架检测auth0-migration— 从其他身份验证提供商迁移auth0-mfa— 多重身份验证设置