---
title: "sdk/android"
description: "Chrome Custom Tabs、PKCE S256 認可コードフロー、Keystore バックアップの EncryptedSharedPreferences トークンストレージを使用した Android 向け Kotlin SDK。"
locale: "ja"
---

> Documentation Index
> Fetch the relevant documentation index at: https://vonvon.id/ja/sdks/llms.txt
> Use this file to discover all available pages before exploring further.

# sdk/android

## 状態

パッケージのステータスは **実装済み・ローカル検証済み** です。JVM 単体テストスイートは成功しており、PKCE、state と nonce の処理、guest capability、storage contracts をカバーしています。EncryptedSharedPreferences、Chrome Custom Tabs、App Links、および実際の IdP ラウンドトリップの検証には、引き続き実機または emulator が必要です。このページは実装済みの動作を説明するものであり、本番対応済みであるとの主張ではありません。

Registry 状態: UNPUBLISHED。この SDK はリポジトリのソース checkout からのみインストールし、外部 package registry は使用しないでください。

## 動作要件

- Android API 26+（Android 8.0）
- Kotlin 1.9+ および AndroidX

## インストール

アプリモジュールの build.gradle.kts に依存関係を追加します：

```kotlin
// settings.gradle.kts
includeBuild("../vonvon/sdk/android")

// app/build.gradle.kts
dependencies {
implementation("dev.vonvon:vonvon-android:0.1.0-alpha.0")
}
```

## マニフェストセットアップ

インテントフィルターでコールバック Activity を登録します。カスタムスキームより App Links（autoVerify 付き HTTPS スキーム）が推奨されます：

```xml
<!-- AndroidManifest.xml -->
<activity android:name=".AuthCallbackActivity" android:exported="true">
<intent-filter android:autoVerify="true">
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
    <data android:scheme="https"
          android:host="yourapp.example.com"
          android:pathPrefix="/auth/callback" />
</intent-filter>
</activity>
```

## クイックスタート

```kotlin
import dev.vonvon.sdk.Vonvon
import dev.vonvon.sdk.model.VonvonConfig

// 1. Initialize in Application.onCreate. offline_access is rejected until DPoP is implemented.
Vonvon.configure(
context = this,
config = VonvonConfig(
    issuer = "https://vonvon.id",
    clientId = "your_client_id",
    redirectUri = "https://yourapp.example.com/auth/callback",
    scopes = listOf("openid", "profile", "email"),
)
)

// 2. Sign in (opens Chrome Custom Tabs)
lifecycleScope.launch { Vonvon.signIn(requireContext()) }

// 3. Handle redirect in AuthCallbackActivity
val session = Vonvon.handleRedirect(intent.data.toString())

// 4. Read the current unexpired session. Expiry requires reauthorization.
val session = Vonvon.getSession()

// 5. Get the current unexpired access token.
val token = Vonvon.getAccessToken()

// 6. Clear local state and optionally open end_session.
Vonvon.signOut(context = this, openEndSession = true)
```

## コア API

| 方式 | 署名 |
| --- | --- |
| `configure` | `fun configure(context: Context, config: VonvonConfig)` |
| `signIn` | `suspend fun signIn(context: Context, options: SignInOptions? = null)` |
| `handleRedirect` | `suspend fun handleRedirect(url: String): VonvonSession` |
| `getSession` | `suspend fun getSession(): VonvonSession?` |
| `getAccessToken` | `suspend fun getAccessToken(options: GetAccessTokenOptions? = null): String` |
| `signOut` | `suspend fun signOut(context: Context? = null, openEndSession: Boolean = false)` |
| `setTokenStorage` | `fun setTokenStorage(adapter: TokenStorageAdapter)` |

## エラー型

すべての SDK エラーは sealed クラス VonvonException のサブタイプです：

| サブクラス | トリガー |
| --- | --- |
| `NotConfigured` | configure() が呼び出されていません |
| `UserCancelled` | ユーザーが完了せずに Custom Tabs を閉じました |
| `StateMismatch` | OAuth state 不一致 — CSRF の可能性があります |
| `TokenExchangeFailed` | トークンエンドポイントがエラーを返しました |
| `TokenValidationFailed` | ID token の署名または claims の検証に失敗しました |
| `NoSession` | サインアウト中に呼び出されたセッションメソッド |

## セキュリティ

- パブリッククライアント — クライアントシークレットは保存・送信されません。
- PKCE S256 のみ。サーバーは plain チャレンジメソッドを拒否します。
- Android Keystore（AES-256-GCM）を使用した EncryptedSharedPreferences が保存時のトークンストアを保護します。
- リクエストごとに生成されるランダムな OAuth state。CSRF を防ぐためリダイレクト時に検証されます。

## 既知の制限事項

- JWKS による ID token 検証は実装済みでローカル単体テスト済みです。L4 には Android 実機または emulator と IdP の検証が必要です。
- ユーザーが認可を完了せずに Custom Tabs を閉じたことを検出するメカニズムがありません。
- シングルアカウント専用 — ストレージレイヤーは固定キーを使用します。

Source: https://vonvon.id/ja/sdks/android/index.mdx
