---
title: "@xid-kit/tauri"
description: "PKCE S256 フロー、ディープリンクコールバックハンドラー、OS キーチェーンアダプター、Rust プラグインテンプレートを備えた Tauri v2 デスクトップ SDK。"
locale: "ja"
---

> Documentation Index
> Fetch the locale documentation index at: https://xid.dev/ja/llms.txt
> Use this file to discover all available pages before exploring further.

# @xid-kit/tauri

## 状態

パッケージステータス：**現行パッケージ**。JS ブリッジ、PKCE S256 フロー、ディープリンクコールバックハンドラー、OS キーチェーンアダプター、Rust プラグインテンプレートが実装済みです。本番インフラでの実際の IdP ラウンドトリップはまだ手動検証待ちです。

## Tauri 設定

```json
// tauri.conf.json
{
  "bundle": { "identifier": "com.example.myapp" },
  "plugins": {
"deep-link": { "desktop": { "schemes": ["myapp"] } }
  }
}
```

## Rust プラグイン

`templates/xid-keychain-plugin.rs` を `src-tauri/src/xid_keychain.rs` にコピーし、`templates/tauri-app-setup.rs` に従って登録します。`src-tauri/Cargo.toml` に `keyring = "2"`、`tauri-plugin-deep-link = "2"`、`tauri-plugin-shell = "2"` を追加します。

## JS 統合

```ts
import { createXidTauriClient, createTauriKeychainAdapter } from '@xid-kit/tauri'
import { invoke } from '@tauri-apps/api/core'
import { open } from '@tauri-apps/plugin-shell'
import { onOpenUrl } from '@tauri-apps/plugin-deep-link'

const client = createXidTauriClient({
  issuer: 'https://xid.dev',
  clientId: 'YOUR_CLIENT_ID',
  redirectUri: 'myapp://auth/callback',
  keychain: createTauriKeychainAdapter({ invoke }),
})

// Register deeplink handler (e.g. on App component mount)
await onOpenUrl(async (urls) => {
  for (const url of urls) await client.handleRedirect(url)
})

// Trigger sign-in: opens system browser
await client.signIn({ openUrl: open })
```

## トークン取得とサインアウト

```ts
// Get current access token (refreshes transparently if near expiry)
const token = await client.getAccessToken()

// Get full session (userId, organizationId, expiresAt)
const session = await client.getSession()

// Revoke server session and clear all keychain entries
await client.signOut()

// OIDC RP-initiated logout URL for full IdP sign-out
const logoutUrl = client.buildSignOutUrl({ postLogoutRedirectUri: 'myapp://logout' })
await open(logoutUrl.toString())
```

## Tauri ランタイムなしの開発/テスト

```ts
import { createXidTauriClient, createMemoryKeychainAdapter } from '@xid-kit/tauri'

const client = createXidTauriClient({
  issuer: 'http://localhost:8788',
  clientId: 'test-client',
  redirectUri: 'http://localhost:1420/callback',
  keychain: createMemoryKeychainAdapter(),
})
```

## createXidTauriClient オプション

| オプション | 種別 | 説明 |
| --- | --- | --- |
| `issuer` | string | XID 発行者 URL |
| `clientId` | string | OAuth 2.0 client\_id |
| `redirectUri` | string | カスタム URI スキームコールバック |
| `scopes` | readonly string\[\] | デフォルト：openid、profile、email |
| `keychain` | XidKeychainAdapter | トークンストレージアダプター。デフォルトは MemoryKeychainAdapter（本番では Tauri アダプターを使用してください） |

## XidTauriClient メソッド

| 方式 | 説明 |
| --- | --- |
| `signIn(options?)` | PKCE 認可 URL を構築します。openUrl コールバック経由で開きます |
| `handleRedirect(url)` | ディープリンクを解析し、state を検証し、コードをトークンと交換します |
| `getSession()` | TauriSession または null。期限切れ間近の場合はトークンを更新します |
| `getAccessToken(options?)` | アクセストークン文字列または null。期限切れ間近の場合は更新します |
| `signOut()` | サーバーセッションを取り消し、キーチェーンをクリアします |
| `buildSignOutUrl(options?)` | RP 起点ログアウト用の OIDC end\_session URL を構築します |
| `setTokenStorage(adapter)` | ランタイム時にキーチェーンアダプターを交換します |

## PKCE とトークンストレージ

- PKCE S256 が常に使用されます。plain チャレンジは生成されません。
- ベリファイアーのエントロピーは 64 バイト。チャレンジは Web Crypto の `crypto.subtle.digest('SHA-256', ...)` で導出されます。
- すべてのキーは `xid.*` 配下に名前空間化されます：`xid.access_token`、`xid.refresh_token`、`xid.session`、`xid.pkce_verifier`、`xid.oauth_state`。

Source: https://xid.dev/ja/sdks/tauri/index.mdx
