kandi-login / Electron

Available

Desktop authentication for Electron apps. Opens the system browser for OAuth, receives the callback via deep-link, and stores tokens securely using Electron safeStorage.

Download Example Project

Quick Start

1

Clone the example project

git clone https://github.com/KandiForge/kandi-packages.git
cd kandi-packages/examples/electron
2

Install dependencies

npm install
3

Start the Electron app

npm start
# Launches the desktop app — pre-configured for the reference server
4

Click "Login" — the system browser opens for OAuth, then returns to the app

Auth Configuration

src/auth.config.ts
// src/auth.config.ts
import { createElectronAuthClient } from '@kandiforge/kandi-login/electron';

export const auth = createElectronAuthClient({
  authServerUrl: 'https://api.packages.kandiforge.com',
  authBasePath: '/api/auth',
  providers: ['google', 'github'],
  // Deep-link scheme registered in package.json
  deepLinkScheme: 'myapp',
  // Tokens stored via Electron safeStorage
  secureStorage: true,
});

Switch to Your Server

The example app points to the KandiForge reference server by default. Once you have your own server running:

// Change authServerUrl to your own server: authServerUrl: 'https://your-api.example.com'

Run the conformance validator against your server to confirm it implements all required endpoints.

Test Personas for Automated Testing

Use the test persona system to authenticate in Playwright, and Spectron tests without launching a browser OAuth flow.

test/auth.setup.tsNo browser needed
// test/auth.setup.ts
import { fetch } from 'electron-fetch';

async function authenticateForTest(personaId: string) {
  // Seed personas (idempotent)
  await fetch('https://your-api.example.com/api/auth/test/seed', {
    method: 'POST',
  });

  // Get real JWT tokens — no browser window needed
  const res = await fetch(
    'https://your-api.example.com/api/auth/test/login-as',
    {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify({ personaId }),
    }
  );
  return res.json();
  // → { access_token, refresh_token, expires_in }
}

Default personas: admin-alex, designer-dana, viewer-val, new-user-naya. See all personas