Skip to content

Commit 2907ad2

Browse files
committed
feat(auth): add command to generate CLI access token
1 parent 0f23527 commit 2907ad2

6 files changed

Lines changed: 152 additions & 83 deletions

File tree

packages/cli/src/commands.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
authLogin,
44
authStatus,
55
authLogout,
6+
authGenerateAccessToken,
67
textChat,
78
textOmni,
89
imageGenerate,
@@ -84,6 +85,7 @@ export const commands: Record<string, AnyCommand> = {
8485
"auth login": authLogin,
8586
"auth status": authStatus,
8687
"auth logout": authLogout,
88+
"auth generate-access-token": authGenerateAccessToken,
8789
"text chat": textChat,
8890
omni: textOmni,
8991
"image generate": imageGenerate,
Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,44 @@
1-
export { generateCLIAccessToken } from "bailian-cli-core";
1+
import {
2+
defineCommand,
3+
detectOutputFormat,
4+
generateCLIAccessToken,
5+
type FlagsDef,
6+
} from "bailian-cli-core";
7+
import { emitResult } from "bailian-cli-runtime";
8+
9+
const FLAGS = {
10+
accessKeyId: {
11+
type: "string",
12+
valueHint: "<id>",
13+
description: "Alibaba Cloud Access Key ID",
14+
required: true,
15+
},
16+
accessKeySecret: {
17+
type: "string",
18+
valueHint: "<secret>",
19+
description: "Alibaba Cloud Access Key Secret",
20+
required: true,
21+
},
22+
} satisfies FlagsDef;
23+
24+
export default defineCommand({
25+
description: "Generate a CLI access token using OpenAPI AK/SK",
26+
auth: "none",
27+
usageArgs: "--access-key-id <id> --access-key-secret <secret>",
28+
flags: FLAGS,
29+
exampleArgs: ["--access-key-id LTAIxxxxx --access-key-secret xxxxx"],
30+
async run(ctx) {
31+
const { identity, settings, flags } = ctx;
32+
const format = detectOutputFormat(settings.output);
33+
34+
const resp = await generateCLIAccessToken({
35+
identity,
36+
settings,
37+
baseUrl: ctx.client.baseUrl,
38+
accessKeyId: flags.accessKeyId,
39+
accessKeySecret: flags.accessKeySecret,
40+
});
41+
42+
emitResult(resp, format);
43+
},
44+
});

packages/commands/src/commands/auth/login.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
runConsoleLogin,
66
validateAndPersistApiKey,
77
} from "./login-console.ts";
8-
import { generateCLIAccessToken } from "./generate-access-token.ts";
8+
import { generateCLIAccessToken } from "bailian-cli-core";
99

1010
const LOGIN_MODE_HINT = "Choose exactly one login mode: --api-key, --console, or --open-api";
1111

packages/commands/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
export { default as authLogin } from "./commands/auth/login.ts";
77
export { default as authStatus } from "./commands/auth/status.ts";
88
export { default as authLogout } from "./commands/auth/logout.ts";
9+
export { default as authGenerateAccessToken } from "./commands/auth/generate-access-token.ts";
910
export { default as textChat } from "./commands/text/chat.ts";
1011
export { default as textOmni } from "./commands/omni/chat.ts";
1112
export { default as imageGenerate } from "./commands/image/generate.ts";

skills/bailian-cli/reference/auth.md

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,36 @@ Index: [index.md](index.md)
77

88
## Commands in this group
99

10-
| Command | Description |
11-
| ---------------- | -------------------------------------------------------------------------------------------- |
12-
| `bl auth login` | Authenticate with API key, console browser login, or OpenAPI AK/SK (credentials can coexist) |
13-
| `bl auth logout` | Clear stored credentials |
14-
| `bl auth status` | Show current authentication state |
10+
| Command | Description |
11+
| ------------------------------- | -------------------------------------------------------------------------------------------- |
12+
| `bl auth generate-access-token` | Generate a CLI access token using OpenAPI AK/SK |
13+
| `bl auth login` | Authenticate with API key, console browser login, or OpenAPI AK/SK (credentials can coexist) |
14+
| `bl auth logout` | Clear stored credentials |
15+
| `bl auth status` | Show current authentication state |
1516

1617
## Command details
1718

19+
### `bl auth generate-access-token`
20+
21+
| Field | Value |
22+
| --------------- | --------------------------------------------------------------------------------- |
23+
| **Name** | `auth generate-access-token` |
24+
| **Description** | Generate a CLI access token using OpenAPI AK/SK |
25+
| **Usage** | `bl auth generate-access-token --access-key-id <id> --access-key-secret <secret>` |
26+
27+
#### Flags
28+
29+
| Flag | Type | Required | Description |
30+
| ------------------------------ | ------ | -------- | ------------------------------- |
31+
| `--access-key-id <id>` | string | yes | Alibaba Cloud Access Key ID |
32+
| `--access-key-secret <secret>` | string | yes | Alibaba Cloud Access Key Secret |
33+
34+
#### Examples
35+
36+
```bash
37+
bl auth generate-access-token --access-key-id LTAIxxxxx --access-key-secret xxxxx
38+
```
39+
1840
### `bl auth login`
1941

2042
| Field | Value |

0 commit comments

Comments
 (0)