---
title: "sdk/macos"
description: "ASWebAuthenticationSession、PKCE S256 認可コードフロー、Keychain トークンストレージを使用した macOS 向け Swift SDK。sdk/ios と実装パターンを共有します。"
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/macos

## 状態

パッケージのステータスは **実装済み・ローカル検証済み** です。Swift 単体テストスイートは macOS 上で成功しています。Keychain access、完全な ASWebAuthenticationSession callback、および実際の IdP ラウンドトリップには、引き続き desktop integration evidence が必要です。このページは実装済みの動作を説明するものであり、本番対応済みであるとの主張ではありません。

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

## 動作要件

- macOS 13+
- Swift 5.9+ および Xcode 15+
- サードパーティ依存関係なし — Apple システムフレームワーク（AuthenticationServices、CryptoKit、Security）のみ使用

## インストール

Package.swift で Swift Package Manager を使って追加します：

```swift
// Package.swift
dependencies: [
.package(path: "../vonvon/sdk/macos"),
],
targets: [
.target(name: "YourApp", dependencies: [.product(name: "Vonvon", package: "macos")]),
]
```

## クイックスタート

```swift
import Vonvon

let client = VonvonClient()

// 1. Configure. offline_access is rejected until DPoP is implemented.
client.configure(VonvonOptions(
issuer: URL(string: "https://vonvon.id")!,
clientId: "your_client_id",
redirectUri: "yourapp://callback"
))

// 2. Sign in (opens ASWebAuthenticationSession)
let session = try await client.signIn()

// 3. Get the current unexpired access token. Expiry requires reauthorization.
let token = try await client.getAccessToken()

// 4. Get the current unexpired session.
let current = try await client.getSession()

// 5. Clear local state and optionally call end_session.
try await client.signOut()
```

## コア API

| 方式 | 説明 |
| --- | --- |
| `configure(_ options:)` | issuer、clientId、redirectUri、scopes を設定します。他のすべてのメソッドより前に呼び出します。 |
| `signIn() async throws -> VonvonSession` | ASWebAuthenticationSession を起動し、PKCE S256 認可コードフローを完了し、トークンを Keychain に永続化してセッションを返します。 |
| `handleRedirect(_ url:) async throws -> VonvonSession` | 外部ソースからのリダイレクト URL を処理し、コードをトークンと交換します。 |
| `getSession() async throws -> VonvonSession?` | 現在の有効期限内の macOS セッションを返します。token state の有効期限が切れている場合は消去し、メソッドは nil を返します。 |
| `getAccessToken() async throws -> String` | 現在の有効期限内の access token を返します。DPoP が実装されるまで SDK は offline\_access を拒否します。有効期限が切れた場合は再認可が必要です。 |
| `signOut() async throws` | Keychain のトークンを消去し、必要に応じて end\_session endpoint を呼び出します。refresh-token の revocation は行いません。 |

## sdk/ios との関係

macOS SDK は sdk/ios と同じ Swift 実装パターンを共有します。ブラウザベースの認可には ASWebAuthenticationSession、PKCE S256 には CryptoKit、トークンストレージには Keychain を使用します。2 つのパッケージはそれぞれ異なる Apple プラットフォームの最小バージョンを対象とし、プラットフォーム固有の権限設定を可能にするために個別に保守されます。

## セキュリティ

- パブリッククライアント — クライアントシークレットは保存・送信されません。
- PKCE S256 のみ。サーバーは plain チャレンジメソッドを拒否します。
- リクエストごとに生成される OAuth state。CSRF を防ぐためリダイレクト時に検証されます。
- トークンはデバイス専用アクセスで Keychain に保存されます。iCloud Keychain には同期されません。

## 既知の制限事項

- JWKS による ES256/RS256 ID token 検証と end\_session logout は実装済みでローカルテスト済みです。L4 には macOS Keychain と IdP の検証が必要です。
- sdk/ios との共有 Swift コア抽出は計画中ですが未実装です。現在は各パッケージが独自の実装コピーを持っています。

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