Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
8151c07
feat(auth): add Aliyun OAuth login with pre-release control-plane iso…
lishengzxc Nov 27, 2026
daca973
Merge origin/main into feat/aliyun-oauth-login
lishengzxc Nov 27, 2026
954665b
fix(auth): harden OAuth session lifecycle and recovery
lishengzxc Nov 27, 2026
24c2156
fix(auth): pin Console retries to the original OAuth session
lishengzxc Nov 27, 2026
7cb4e95
feat(auth): add cross-device Aliyun OAuth login
lishengzxc Nov 27, 2026
8dcbe85
feat(auth): move OAuth login to auth login --oauth with international…
lishengzxc Nov 28, 2026
df3e660
test(auth): cover OAuth site/region matrix and resolve BAILIAN_PRE in…
lishengzxc Nov 28, 2026
4d13dcf
docs(auth): document auth login --oauth and international pre-release…
lishengzxc Nov 28, 2026
6934e38
feat(auth): fill confirmed international pre-release OAuth and consol…
lishengzxc Nov 28, 2026
65e11a7
feat(auth): enable international pre-release OAuth login with confirm…
lishengzxc Nov 30, 2026
f07c6dd
fix(auth): address CR findings on workspace init auth domain and OAut…
lishengzxc Nov 30, 2026
c520e4a
Merge remote-tracking branch 'origin/main' into feat/aliyun-oauth-login
lishengzxc Dec 1, 2026
b96e57c
fix(auth): harden OAuth session lifecycle and pre-release site routing
lishengzxc Dec 1, 2026
b8b5955
Merge remote-tracking branch 'origin/main' into feat/aliyun-oauth-login
lishengzxc Dec 1, 2026
ef4558c
chore(release): prepare 2.16.0
lishengzxc Dec 1, 2026
2f143e8
feat(auth): build in online OAuth defaults per site and open internat…
lishengzxc Dec 1, 2026
2704546
Merge remote-tracking branch 'origin/main' into feat/aliyun-oauth-login
lishengzxc Dec 2, 2026
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,24 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and

[中文版](CHANGELOG.zh.md) · [README](README.md) · [Contributing](CONTRIBUTING.md)

## [2.16.0] - 2026-12-01

> Aliyun OAuth login: `bl auth login --oauth` exchanges a browser authorization for an auto-renewing console session.

### Added

- **Aliyun OAuth login**: `bl auth login --oauth` signs in with an Aliyun account (China site by default; `--console-site international` for the international site) and keeps the console session and OpenAPI credentials renewed automatically. OAuth credentials coexist with API key, console and AK/SK credentials.
- `--no-browser` prints the authorization URL for another device; paste the full callback URL back to finish login without a local port listener.

### Changed

- **`bl auth generate-access-token`**: AK/SK flags are now optional — the command reuses saved OpenAPI credentials (including OAuth-managed sessions); `--access-key-id` / `--access-key-secret` are only needed when no credentials are stored.
- **`bl auth status`**: reports the Aliyun OAuth session and OAuth-managed console/OpenAPI credentials.

### Fixed

- **Token Plan international routing**: `bl token-plan` commands recognize the international Model Studio endpoint (`modelstudio.ap-southeast-1.aliyuncs.com`) and route to the intl OpenAPI host instead of misrouting by region preset.

## [2.15.1] - 2026-12-02

### Added
Expand Down
18 changes: 18 additions & 0 deletions CHANGELOG.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,24 @@

[English](CHANGELOG.md) · [README](README.zh.md) · [参与贡献](CONTRIBUTING.zh.md)

## [2.16.0] - 2026-12-01

> 阿里云 OAuth 登录:`bl auth login --oauth` 通过浏览器授权换取自动续期的控制台会话。

### 新增

- **阿里云 OAuth 登录**:`bl auth login --oauth` 使用阿里云账号登录(默认中国站;国际站使用 `--console-site international`),控制台会话与 OpenAPI 凭证自动续期。OAuth 凭证与 API Key、控制台、AK/SK 凭证可共存。
- `--no-browser` 打印授权地址供其它设备授权,粘贴完整回调 URL 即可完成登录,不监听本地端口。

### 变更

- **`bl auth generate-access-token`**:AK/SK 参数改为可选——命令复用已保存的 OpenAPI 凭证(含 OAuth 托管会话);仅在未保存凭证时才需要 `--access-key-id` / `--access-key-secret`。
- **`bl auth status`**:展示阿里云 OAuth 会话与 OAuth 托管的控制台/OpenAPI 凭证。

### 修复

- **Token Plan 国际站路由**:`bl token-plan` 命令识别国际站 Model Studio 端点(`modelstudio.ap-southeast-1.aliyuncs.com`),正确路由到 intl OpenAPI 主机,不再因区域预设误判。

## [2.15.1] - 2026-12-02

### 新增
Expand Down
41 changes: 38 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,44 @@ Synchronous Batch Chat is non-streaming; explicit realtime/international/Token P

## Authentication

### Console Login (OAuth, Recommended)
### Aliyun OAuth

Required for console capability commands (model list, flow-agent list, workspace, usage queries, rate-limit increases, direct console calls). It can create an ordinary API key when needed. Token Plan and other subscription plans cannot use `--console`; use the API Key login below.
`bl auth login --oauth` uses authorization code + PKCE, exchanges OAuth credentials for STS, and uses STS to obtain the Bailian Console token and sign OpenAPI requests. `--console-site <domestic|international>` selects the site (default `domestic`). The official IAM application ID and the authorization/token endpoints are built in for both sites, so a first online login needs no endpoint flags:

```bash
bl auth login --oauth --config aliyun
```

Register `http://127.0.0.1:12345/oauth/callback` as the IAM redirect URI. NativeApp loopback callbacks allow a random port, but the scheme, host and path must match. The CLI accepts only `/oauth/callback`, not the root path or an extra trailing `/`.

Online endpoints resolve in the order explicit flags > selected Profile > defaults. Later logins can reuse the saved application ID and endpoints. `--dry-run` previews the plan without opening a browser, reading credential files or exchanging credentials. `--console-region <cn-beijing|ap-southeast-1>` only sets the `console_region` saved to config.json and the Console routing; the OAuth authorization/token/exchange endpoints follow the site alone. It defaults to `cn-beijing` for domestic and `ap-southeast-1` for international.

International site: `bl auth login --oauth --console-site international`. The international IAM application is approved for both pre-release and production with its client ID built in; online login automatically uses the international signin/oauth domains, and pre-release login works like the domestic one.

For SSH, containers or other environments without a browser, add `--no-browser`. Open the generated link on a computer or phone, authorize, then paste the entire redirected URL (including `code` and `state`) back into the same CLI session. The callback is `http://127.0.0.1:12345/oauth/callback`; no port is opened and the browser's connection error is expected. Input is hidden only when the CLI can disable echo on a terminal; otherwise it warns that the callback URL may be visible. For interactive SSH, use `ssh -t user@host 'bl auth login --oauth --no-browser'`; in Docker, allocate a TTY with `docker exec -it`. The CLI does not save the URL in input history. This is interactive cross-device authorization, not device-code login or unattended CI authentication.

```bash
bl auth login --oauth --config aliyun --no-browser
```

The example works for a first login too; `--client-id` and `--authorization-url` are optional overrides of the built-in defaults.

#### Domestic pre-release control plane

Set `BAILIAN_PRE=1` (or `true`) to select the pre-release control plane: domestic `cn-beijing`, or international `ap-southeast-1` with `--console-site international`. Unset, empty, `0` or `false` selects the online environment. Pre-release Profiles live under a separate `pre/` config directory and do not inherit online Console credentials or general AK/SK environment variables. DashScope inference keeps its existing connection and Profile selection.

```bash
BAILIAN_PRE=1 bl auth login --oauth --dry-run
BAILIAN_PRE=1 bl auth status
```

Supported OAuth and OpenAPI routes are selected automatically. Confirm the pre-release CLI gateway protocol before supplying `BAILIAN_PRE_CONSOLE_GATEWAY`. Native Console browser login also requires a confirmed login and callback origin via `BAILIAN_PRE_CONSOLE_ORIGIN`. The CLI does not change hosts or proxy configuration. Unsupported regions and management services do not fall back to online endpoints. MCP management and cloud Skill commands are an exception: they stay on the existing API key and workspace routes and do not switch to pre-release.

Aliyun OAuth credentials are stored as **plaintext** in a separate `oauth/<session_ref>.json` file under the CLI config directory, not in the main config. Writes are atomic; the cache directory and files use `0700` and `0600` on Unix, and Windows requires private ACLs. No Keychain or system credential service is used. Keep this directory private and out of shared backups. Sign in again if you used the previous encrypted format; it is not migrated. OAuth refresh and STS renewal are shared across Console and OpenAPI calls. `auth status` only describes configured credentials; it does not validate or refresh them. Full `auth logout` or `auth logout --aliyun` revokes the RT; partial `--console`/`--open-api` logout disables only that domain. OAuth login preserves existing API keys and does not provision inference keys, initialize workspaces, modify hosts/proxies, or activate paid services.

### Console Browser Login (Recommended)

Console capability commands (model list, flow-agent list, workspace, usage queries, rate-limit increases, direct console calls) can use this browser login or Aliyun OAuth above. Browser login can create an ordinary API key when needed outside pre-release. Token Plan and other subscription plans cannot use `--console` for inference; use the API Key login below.

```bash
bl auth login --console
Expand Down Expand Up @@ -251,7 +286,7 @@ Get an ordinary key from the [DashScope Console](https://bailian.console.aliyun.

### Alibaba Cloud OpenAPI AK/SK

Token Plan seat/member management and console token refresh need an Alibaba Cloud AccessKey. Run the setup guide, or get keys from the [RAM Console](https://ram.console.aliyun.com/manage/ak) and paste them.
Token Plan seat and member management and Console token refresh require OpenAPI credentials: Alibaba Cloud AccessKey/STS credentials or an Aliyun OAuth session. Online, run the AccessKey setup guide or get keys from the [RAM Console](https://ram.console.aliyun.com/manage/ak). The browser guide is not available in pre-release; use explicit pre-release AccessKey credentials or Aliyun OAuth instead.

> Recommended: create a RAM sub-account with minimum privileges instead of using the root account's AK/SK.

Expand Down
41 changes: 38 additions & 3 deletions README.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,44 @@ bl text chat --batch --model qwen-plus --message "你好" --timeout 3600

## 认证方式

### 控制台登录(OAuth,推荐)
### 阿里云 OAuth

控制台能力命令(模型列表、应用列表、工作空间、用量查询、限流提额、控制台直调)需要使用此登录方式,并可在需要时创建普通 API Key。Token Plan 等订阅计划不能使用 `--console`,请使用下面的 API Key 登录方式。
`bl auth login --oauth` 使用授权码与 PKCE 获取 OAuth 凭据,再置换 STS;STS 同时用于获取百炼 Console token 和签名调用 OpenAPI。`--console-site <domestic|international>` 选择站点(缺省 `domestic`)。正式 IAM 应用 ID 与授权/换票端点已按站点内置,线上首次登录无需任何端点参数:

```bash
bl auth login --oauth --config aliyun
```

IAM 重定向 URI 应登记为 `http://127.0.0.1:12345/oauth/callback`。NativeApp 本机回环回调允许随机端口,但协议、主机和路径必须一致;CLI 仅接受 `/oauth/callback`,不接受根路径或末尾额外的 `/`。

线上端点按显式参数 > 所选 Profile > 默认地址解析;之后可以复用已保存的应用 ID 和端点。`--dry-run` 仅展示计划,不打开浏览器、不读凭据文件、不换票。`--console-region <cn-beijing|ap-southeast-1>` 只决定写入 config.json 的 `console_region` 与控制台路由;OAuth 授权/换票端点仅由站点决定。缺省按站点推导:国内 `cn-beijing`,国际 `ap-southeast-1`。

国际站:`bl auth login --oauth --console-site international`。国际站预发与线上 IAM 应用均已获批,client ID 已内置;线上登录自动使用国际站 signin/oauth 域名,预发登录方式与国内一致。

SSH、容器等无法打开浏览器的环境可加 `--no-browser`:在电脑或手机上打开本次生成的链接并授权,再把地址栏中完整的回调 URL(含 `code` 和 `state`)粘回同一个 CLI 会话。回调地址为 `http://127.0.0.1:12345/oauth/callback`,不监听端口,浏览器提示连接失败是正常现象。只有 CLI 能关闭终端回显时才隐藏输入,否则会提醒回调 URL 可能被显示。通过 SSH 交互登录时,用 `ssh -t user@host 'bl auth login --oauth --no-browser'`;在 Docker 里,用 `docker exec -it` 分配 TTY。CLI 不会把回调 URL 保存到输入历史。这仍需人工授权,不是设备码登录或无人值守的 CI 鉴权。

```bash
bl auth login --oauth --config aliyun --no-browser
```

示例同样适用于首次登录;`--client-id` 与 `--authorization-url` 仅用于覆盖内置默认。

#### 国内预发控制面

用 `BAILIAN_PRE=1`(也接受 `true`)切换预发控制面:国内 `cn-beijing`,或配合 `--console-site international` 使用国际 `ap-southeast-1`;未设置、空值、`0` 或 `false` 使用线上。预发 Profile 独立保存在配置目录下的 `pre/`,不会复用线上控制台凭据或通用 AK/SK 环境变量。DashScope 推理的连接和 Profile 选择不变。

```bash
BAILIAN_PRE=1 bl auth login --oauth --dry-run
BAILIAN_PRE=1 bl auth status
```

预发 OAuth 和已支持的 OpenAPI 端点自动选择。启用 Console 调用前,须确认预发 CLI 网关协议并设置 `BAILIAN_PRE_CONSOLE_GATEWAY`;使用原生浏览器登录还须确认登录页和回调可信源,并设置 `BAILIAN_PRE_CONSOLE_ORIGIN`。CLI 不改变 hosts/代理。未经确认的地域和管理服务不会自动改走线上。MCP 管理与云端 Skill 不受此开关影响,仍使用原有的 API Key 和工作空间路由,不切换到预发。

阿里云 OAuth 凭据以**明文**存放在配置目录下独立的 `oauth/<session_ref>.json` 中,不写入主配置。文件采用原子写入;Unix 上目录和文件分别为 `0700` 和 `0600`,Windows 要求私有 ACL。不使用钥匙串或系统凭据服务,请勿共享或备份到不受保护的位置。旧加密会话不迁移,需要重新登录。Console 与 OpenAPI 共享 OAuth/STS 续期。`auth status` 仅展示当前配置,不在线验证或刷新;完整 `auth logout` 或 `auth logout --aliyun` 会撤销 RT,部分 `--console`/`--open-api` 退出仅停用对应域。OAuth 登录保留已有模型 API Key,不创建推理密钥、不初始化工作空间、不改 hosts/代理,也不自动开通付费服务。

### 控制台浏览器登录(推荐)

控制台能力命令(模型列表、应用列表、工作空间、用量查询、限流提额、控制台直调)可使用此浏览器登录或上面的阿里云 OAuth。非预发环境下,浏览器登录可按需创建普通 API Key。Token Plan 等订阅计划推理不能使用 `--console`,请使用下面的 API Key 登录方式。

```bash
bl auth login --console
Expand Down Expand Up @@ -250,7 +285,7 @@ bl auth login --api-key <API_KEY>

### 阿里云 OpenAPI AK/SK

Token Plan 的席位与成员管理、以及控制台会话换票需要阿里云 AccessKey。可先运行引导获取,或前往 [RAM 控制台](https://ram.console.aliyun.com/manage/ak) 获取后粘贴。
Token Plan 的席位与成员管理及控制台换票需要 OpenAPI 凭据,可使用阿里云 AccessKey/STS 或阿里云 OAuth 会话。线上可运行配置引导,或前往 [RAM 控制台](https://ram.console.aliyun.com/manage/ak) 获取 AccessKey。预发不提供浏览器引导,请显式提供预发 AccessKey 或使用阿里云 OAuth。

> 建议:创建 RAM 子账号并授予最小权限,避免使用主账号 AK/SK。

Expand Down
Loading