Authdog SDK for Electron desktop apps — sign-in
via the system browser with a deep-link callback, a pluggable token store, and
user resolution against the OIDC userinfo endpoint. Built on
@authdog/node-commons, so public-key parsing and the
trusted identity-host allowlist are shared with the rest of the Authdog Web SDK.
bun add @authdog/electronElectron itself stays a dependency of your app, not of this package. Pass
shell.openExternal (or createElectronOpener(shell)) so sign-in opens the
system browser, and register a custom protocol so the OS can deliver the
callback.
import { app, shell } from "electron";
import { createAuthdogClient, createElectronOpener } from "@authdog/electron";
const authdog = createAuthdogClient({
publicKey: "pk_…",
redirectUri: "myapp://auth/callback",
openUrl: createElectronOpener(shell),
});
if (process.defaultApp) {
if (process.argv.length >= 2) {
app.setAsDefaultProtocolClient("myapp", process.execPath, [
process.argv[1],
]);
}
} else {
app.setAsDefaultProtocolClient("myapp");
}
app.on("open-url", (_event, url) => {
void authdog.handleCallback(url);
});
signinButton.on("click", () => void authdog.signIn());
signoutButton.on("click", () => void authdog.signOut());signIn({ prompt? })/signUp()— build the OIDCauthorizeURL and open it withopenUrl(defaults towindow.openin a renderer). The provider redirects to yourredirectUrideep link.handleCallback(url)— extracts the token from the deep-link URL (query or fragment, custom schemes supported), persists JWT-shaped values, and returns the token ornull.getToken()/isAuthenticated()— read the persisted token from the configuredTokenStorage(defaults tolocalStoragewhen a window exists; injectsafeStoragein the main process).getUser()— callsuserinfowith the stored token; returns the user ornull. Never throws.signOut()— clears the persisted token.
- The public key is validated and parsed once; a malformed or untrusted key (identity host not on the allowlist) throws immediately.
- Credentials never pass through the app window — sign-in happens in the system
browser. Only JWT-shaped tokens are persisted, and the token is only ever sent
to the trusted,
https:identity host enforced by@authdog/node-commons. isAuthenticated()reflects token presence only — a UI hint. Enforce every protected operation server-side.
MIT