认证
Shoplazza CLI v2 使用 OAuth 2.0 + PKCE 进行安全认证。本指南涵盖交互式登录、CI/CD 非交互式认证、作用域管理和多店铺工作流。
交互式登录(浏览器)
标准认证流程会打开浏览器进行 OAuth 授权:
shoplazza auth login --store-domain my-store.myshoplaza.com
流程:
- CLI 在 Shoplazza 合作伙伴平台创建 OAuth 会话
- 浏览器窗口打开,等待你授权
- 授权后,CLI 接收并存储凭证
- 凭证保存在操作系统原生钥匙链中(macOS Keychain / Windows 凭据管理器 / Linux Secret Service)
登录时指定作用域
使用 --domain 请求特定业务域的访问权限:
shoplazza auth login --store-domain my-store.myshoplaza.com --domain products,orders,customers
或使用 --scope 精细控制 OAuth 作用域:
shoplazza auth login --store-domain my-store.myshoplaza.com --scope read_product,write_product,read_order
查看可用作用域
shoplazza auth scopes
非交互式登录(CI/CD)
在 CI/CD 流水线和自动化环境中,使用用户访问令牌(UAT):
shoplazza auth login --uat <your-token> --store-domain my-store.myshoplaza.com
或设置环境变量:
export SHOPLAZZA_UAT=your-token
export SHOPLAZZA_STORE=my-store.myshoplaza.com
shoplazza products +search --keyword "shirt"
提示
从 Shoplazza 合作伙伴后台生成 UAT。将其作为密钥存储在 CI/CD 系统中——切勿提交到源代码仓库。
查看认证状态
shoplazza auth status
显示内容:当前账户、连接的店铺、已授权的 OAuth 作用域、令牌过期时间。
切换店铺
无需注销即可切换到另一个店铺:
shoplazza auth store use --store-domain another-store.myshoplaza.com
注销
移除所有存储的凭证:
shoplazza auth logout
警告
注销会从操作系统钥匙链中删除所有存储的令牌。下次使用 CLI 时需要重新认证。
作用域映射
| 模块 | 所需作用域 |
|---|---|
products | read_product, write_product |
orders | read_order, write_order |
customers | read_customer, write_customer |
discounts | read_discount, write_discount |
shop | read_shop, write_shop |
billing | read_billing, write_billing |
webhook | read_webhook, write_webhook |
themes | read_theme, write_theme |
如果令牌缺少所需作用域,CLI 会返回清晰的错误信息和重新认证的提示。
安全最佳实践
- 使用操作系统钥匙链 — 凭证存储在操作系统原生安全存储中,而非明文配置文件
- 定期轮换令牌 — 定期重新认证以刷新令牌
- 最小作用域 — 只请求工作流所需的作用域
- CI/CD 密钥 — 将 UAT 令牌作为加密密钥存储在 CI/CD 系统中
- 不要提交令牌 — 将
.shoplazza/添加到.gitignore