---
title: "@vonvon-kit/electron"
description: "Electron SDK with main process PKCE flow, contextBridge preload, OS keychain token storage, and loopback or custom-scheme callback strategies."
locale: "en"
---

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

# @vonvon-kit/electron

## Status

Registry status: UNPUBLISHED. Install this SDK only from the repository source checkout; do not use an external package registry.

Package status is **Current package**. Main process app, contextBridge preload, and renderer-side bridge are implemented. A real IdP round-trip on production infrastructure is still pending manual verification.

## Entry points

| Entry | Purpose |
| --- | --- |
| `@vonvon-kit/electron` | Default export: renderer surface and types |
| `@vonvon-kit/electron/main` | Main process only: VonvonElectronApp |
| `@vonvon-kit/electron/renderer` | Renderer process: getVonvonBridge, VonvonClient |
| `@vonvon-kit/electron/preload` | Ready-made preload script that exposes window.vonvonBridge |

## Main process setup

```ts
// main.ts
import { app, ipcMain } from 'electron'
import { VonvonElectronApp } from '@vonvon-kit/electron/main'

const vonvonApp = new VonvonElectronApp({
  issuer: 'https://vonvon.id',
  clientId: 'client_abc123',
  // callbackStrategy: 'loopback' (default, RFC 8252 s.7.3) | 'custom-scheme'
})

app.whenReady().then(async () => {
  await vonvonApp.init(ipcMain)
  const win = new BrowserWindow({
webPreferences: {
  contextIsolation: true,
  preload: path.join(__dirname, 'preload.js'),
},
  })
  win.on('closed', () => vonvonApp.dispose(ipcMain))
})
```

## Preload script

```ts
// preload.ts
import '@vonvon-kit/electron/preload'
// Exposes window.vonvonBridge with storage, signIn, signOut,
// getAccessToken, getSession, setTokenStorage
```

## Renderer process

```ts
import { getVonvonBridge } from '@vonvon-kit/electron/renderer'

const bridge = getVonvonBridge()

// Opens system browser, waits for loopback callback, exchanges code.
const accessToken = await bridge.signIn()

// Get the current unexpired access token. Expiry requires a new sign-in.
const token = await bridge.getAccessToken() // null when signed out or expired

// Get the current unexpired session (accessToken + expiresAt in epoch seconds).
const session = await bridge.getSession()

// Clear local tokens. No refresh or revoke request is sent.
await bridge.signOut()
```

## Custom scheme (alternative to loopback)

```ts
// main.ts
import { app } from 'electron'
import { VonvonElectronApp } from '@vonvon-kit/electron/main'

app.setAsDefaultProtocolClient('myapp')

const vonvonApp = new VonvonElectronApp({
  issuer: 'https://vonvon.id',
  clientId: 'client_abc123',
  callbackStrategy: 'custom-scheme',
  customScheme: 'myapp',  // redirect_uri = myapp://callback
})

vonvonApp.registerDeepLinkHandler(app)
```

## Token storage

- Tokens are encrypted with `safeStorage.encryptString()` (OS keychain) and stored as binary files in `app.getPath('userData')/vonvon-tokens/` by default.
- If `safeStorage.isEncryptionAvailable()` returns `false` (headless Linux without a keyring), `setItem()` throws `ElectronStorageError` with code `encryption_unavailable` rather than writing plaintext silently.
- Override the storage directory with `storageDir` in `VonvonElectronMainOptions`.

## Shared native contract

| Method | Description |
| --- | --- |
| `signIn(options?)` | Opens system browser, exchanges code, stores tokens |
| `signOut()` | Clears local tokens |
| `getAccessToken()` | Returns the current unexpired access token without refresh; clears expired local state and returns null. The SDK rejects offline\_access until DPoP is implemented. |
| `getSession()` | Returns the current unexpired accessToken and expiresAt, or null |

Source: https://vonvon.id/sdks/electron/index.mdx
