Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .cspell/dicts/project.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ anstream
coderabbitai
nulab
truecolor
getrandom
CSPRNG
subsec
38 changes: 38 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ rpassword = "7"
keyring = { version = "3", default-features = false, features = ["async-secret-service", "crypto-rust"] }
anstream = "0.6"
owo-colors = "4"
open = "5"
getrandom = "0.3"

[target.'cfg(windows)'.dependencies]
keyring = { version = "3", features = ["windows-native"] }
Expand Down
62 changes: 56 additions & 6 deletions docs/user-guide.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
## 前提条件

- 少なくとも 1 つのスペースにアクセスできる [Backlog](https://backlog.com) アカウント
- Backlog API キー([認証](#認証) を参照)
- Backlog API キーまたは OAuth 2.0 クライアント認証情報([認証](#認証) を参照)

## インストール

Expand Down Expand Up @@ -104,7 +104,7 @@ irm https://raw.githubusercontent.com/23prime/backlog-cli/latest/uninstall.ps1 |
3. メモを入力して **送信** をクリックします
4. 生成された API キーをコピーします

### ログイン
### API キーでログイン

```bash
bl auth login
Expand All @@ -119,6 +119,41 @@ bl auth login
別のスペースキーで `bl auth login` を再実行すると、そのスペースが追加されます。
最後にログインしたスペースがカレント(アクティブ)スペースになります。

### OAuth 2.0 でログイン

API キーの代わりに、ブラウザベースの OAuth 2.0 認証を使用できます。

#### ステップ 1 — Backlog で OAuth アプリケーションを登録する

1. <https://backlog.com/developer/applications/oauth2Clients/add> を開きます
2. 新しいアプリケーションを作成します:
- **アプリケーション種別**: Confidential Client
- **リダイレクト URI**: `http://127.0.0.1:54321/callback`
(`--port <port>` を使用する場合は `http://127.0.0.1:<port>/callback`)
3. **クライアント ID** と **クライアントシークレット** を控えておきます

#### ステップ 2 — OAuth ログインコマンドを実行する

```bash
bl auth login-oauth
```

以下の入力を求められます。

- **スペースキー** — Backlog スペースのサブドメイン
- **クライアント ID** — 登録したアプリケーションのクライアント ID
- **クライアントシークレット** — 登録したアプリケーションのクライアントシークレット(入力は非表示)

コマンドを実行するとブラウザが開き、Backlog の認証画面が表示されます。
承認後、ブラウザは `http://127.0.0.1:54321/callback` にリダイレクトされ、
アクセストークンが自動的に保存されます。

カスタムポートを使用する場合(Backlog に登録したリダイレクト URI と一致させてください):

```bash
bl auth login-oauth --port 8080
```

### 複数スペースの管理

```bash
Expand Down Expand Up @@ -151,11 +186,23 @@ Backlog API に対して認証情報を検証し、以下のように表示し

```text
Space: mycompany.backlog.com
- Auth method: API key
- API key: abcd...
- Stored in: System keyring
- Logged in as Your Name (your-id)
```

OAuth 2.0 認証の場合:

```text
Space: mycompany.backlog.com
- Auth method: OAuth 2.0
- Client ID: abc123
- Client Secret: abcd...
- Access token: abcd...
- Logged in as Your Name (your-id)
```

`BL_API_KEY` が設定されている場合、`Stored in` には `Environment variable` と表示されます。

### ログアウト
Expand Down Expand Up @@ -186,6 +233,7 @@ bl auth logout --all
| コマンド | 説明 |
| --- | --- |
| `bl auth login` | Backlog API キーで認証(スペースを追加または更新)。`--no-banner` でバナーをスキップ |
| `bl auth login-oauth` | ブラウザベースの OAuth 2.0 で認証。`--port <port>` でコールバックポートを変更(デフォルト: 54321)。`--no-banner` でバナーをスキップ |
| `bl auth status` | 現在の認証状態を表示して認証情報を検証 |
| `bl auth list` | 設定済みスペースの一覧を表示 |
| `bl auth use <space-key>` | カレントスペースを切り替え |
Expand Down Expand Up @@ -799,16 +847,18 @@ bl wiki attachment list 12345 --json
| 場所 | 内容 |
| --- | --- |
| `~/.config/bl/config.toml` | スペースキー(非機密メタデータ) |
| システムキーリング | API キー(優先; GNOME Keyring / Keychain) |
| システムキーリング | API キーと OAuth トークン(優先; GNOME Keyring / Keychain) |
| `~/.config/bl/credentials.toml` | API キーのフォールバック(mode 0600、キーリングが使えない場合) |
| `~/.config/bl/oauth_tokens.toml` | OAuth トークンのフォールバック(mode 0600、キーリングが使えない場合) |

### Windows

| 場所 | 内容 |
| --- | --- |
| `%APPDATA%\bl\config.toml` | スペースキー(非機密メタデータ) |
| Windows 資格情報マネージャー | API キー(優先) |
| Windows 資格情報マネージャー | API キーと OAuth トークン(優先) |
| `%APPDATA%\bl\credentials.toml` | API キーのフォールバック(資格情報マネージャーが使えない場合) |
| `%APPDATA%\bl\oauth_tokens.toml` | OAuth トークンのフォールバック(資格情報マネージャーが使えない場合) |

### 設定ファイルの形式

Expand Down Expand Up @@ -837,10 +887,10 @@ API キーがキーリングに見つかりません。`bl auth login` を再実
### キーリングが利用できない

Linux では、キーリングには Secret Service デーモン(GNOME Keyring または KWallet)が起動している必要があります。
デーモンが利用できない場合(ヘッドレス環境や SSH 経由など)、`bl` は自動的に `~/.config/bl/credentials.toml`mode 0600)にフォールバックします
デーモンが利用できない場合(ヘッドレス環境や SSH 経由など)、`bl` は API キーを `~/.config/bl/credentials.toml`、OAuth トークンを `~/.config/bl/oauth_tokens.toml`(いずれも mode 0600)に自動的にフォールバックします

macOS ではシステムの Keychain、Windows では Windows 資格情報マネージャーが使用されます。
資格情報マネージャーが利用できない場合は `%APPDATA%\bl\credentials.toml` にフォールバックします。
資格情報マネージャーが利用できない場合は、API キーは `%APPDATA%\bl\credentials.toml`、OAuth トークンは `%APPDATA%\bl\oauth_tokens.toml` にフォールバックします。

`bl auth status` の出力で使用中のバックエンドを確認できます。

Expand Down
64 changes: 58 additions & 6 deletions docs/user-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
## Prerequisites

- A [Backlog](https://backlog.com) account with access to at least one space
- A Backlog API key (see [Authentication](#authentication))
- A Backlog API key or OAuth 2.0 client credentials (see [Authentication](#authentication))

## Installation

Expand Down Expand Up @@ -108,7 +108,7 @@ To also remove stored credentials and configuration files, pass `-Purge`:
3. Enter a memo and click **Submit**
4. Copy the generated API key

### Logging in
### Logging in with an API key

```bash
bl auth login
Expand All @@ -123,6 +123,41 @@ You will be prompted for:
Running `bl auth login` again with a different space key adds another space.
The most recently logged-in space becomes the current (active) space.

### Logging in with OAuth 2.0

`bl` supports browser-based OAuth 2.0 login as an alternative to API keys.

#### Step 1 — Register an OAuth application in Backlog

1. Open <https://backlog.com/developer/applications/oauth2Clients/add>
2. Create a new application:
- **Application type**: Confidential Client
- **Redirect URI**: `http://127.0.0.1:54321/callback`
(use `http://127.0.0.1:<port>/callback` if you will pass `--port <port>`)
3. Note the **Client ID** and **Client Secret**

#### Step 2 — Run the OAuth login command

```bash
bl auth login-oauth
```

You will be prompted for:

- **Space key** — the subdomain of your Backlog space
- **Client ID** — from the registered application
- **Client Secret** — from the registered application (input is hidden)

The command opens your browser to the Backlog authorization page.
After you approve, the browser is redirected to `http://127.0.0.1:54321/callback`
and the access token is stored automatically.

To use a custom port (must match the Redirect URI registered in Backlog):

```bash
bl auth login-oauth --port 8080
```

### Managing multiple spaces

```bash
Expand Down Expand Up @@ -155,11 +190,23 @@ This verifies your credentials against the Backlog API and shows:

```text
Space: mycompany.backlog.com
- Auth method: API key
- API key: abcd...
- Stored in: System keyring
- Logged in as Your Name (your-id)
```

When authenticated via OAuth:

```text
Space: mycompany.backlog.com
- Auth method: OAuth 2.0
- Client ID: abc123
- Client Secret: abcd...
- Access token: abcd...
- Logged in as Your Name (your-id)
```

When `BL_API_KEY` is set, `Stored in` shows `Environment variable`.

### Logging out
Expand Down Expand Up @@ -190,6 +237,7 @@ bl auth logout --all
| Command | Description |
| --- | --- |
| `bl auth login` | Authenticate with a Backlog API key (adds or updates a space); use `--no-banner` to skip the banner |
| `bl auth login-oauth` | Authenticate via browser-based OAuth 2.0; use `--port <port>` to override the default callback port (54321); use `--no-banner` to skip the banner |
| `bl auth status` | Show current auth status and verify credentials |
| `bl auth list` | List all configured spaces |
| `bl auth use <space-key>` | Switch the current space |
Expand Down Expand Up @@ -804,16 +852,18 @@ Commands that target a specific project accept a `--project <key>` flag.
| Location | Contents |
| --- | --- |
| `~/.config/bl/config.toml` | Space key (non-sensitive metadata) |
| System keyring | API key (primary; GNOME Keyring / Keychain) |
| System keyring | API key and OAuth tokens (primary; GNOME Keyring / Keychain) |
| `~/.config/bl/credentials.toml` | API key fallback (mode 0600, used when keyring is unavailable) |
| `~/.config/bl/oauth_tokens.toml` | OAuth token fallback (mode 0600, used when keyring is unavailable) |

### Windows

| Location | Contents |
| --- | --- |
| `%APPDATA%\bl\config.toml` | Space key (non-sensitive metadata) |
| Windows Credential Manager | API key (primary) |
| Windows Credential Manager | API key and OAuth tokens (primary) |
| `%APPDATA%\bl\credentials.toml` | API key fallback (used when Credential Manager is unavailable) |
| `%APPDATA%\bl\oauth_tokens.toml` | OAuth token fallback (used when Credential Manager is unavailable) |

### Config file format

Expand Down Expand Up @@ -843,10 +893,12 @@ Run `bl auth login` to re-enter your credentials.

On Linux, the keyring requires a running Secret Service daemon (GNOME Keyring or KWallet).
If no daemon is available (e.g. headless or SSH environments), `bl` automatically falls back
to storing the API key in `~/.config/bl/credentials.toml` with mode 0600.
to storing the API key in `~/.config/bl/credentials.toml` and OAuth tokens in
`~/.config/bl/oauth_tokens.toml`, both with mode 0600.

On macOS, the system Keychain is used. On Windows, the Windows Credential Manager is used.
If the Credential Manager is unavailable, `bl` falls back to `%APPDATA%\bl\credentials.toml`.
If the Credential Manager is unavailable, `bl` falls back to `%APPDATA%\bl\credentials.toml`
(API key) and `%APPDATA%\bl\oauth_tokens.toml` (OAuth tokens).

The `bl auth status` output shows which backend is in use:

Expand Down
Loading