Electron app
The casdoor-electron-example shows Casdoor sign-in in an Electron app (custom protocol + browser OAuth).
Run the example
Initialization
Set these 6 string parameters:
| Name | Description | Path |
|---|---|---|
| serverUrl | Your Casdoor server URL | src/App.js |
| clientId | The Client ID of your Casdoor application | src/App.js |
| appName | The name of your Casdoor application | src/App.js |
| redirectPath | The path of the redirect URL for your Casdoor application, will be /callback if not provided | src/App.js |
| clientSecret | The Client Secret of your Casdoor application | src/App.js |
| casdoorServiceDomain | Your Casdoor server URL | public/electron.js |
Defaults: Casdoor demo and app-casnode if not set.
Commands
In the project directory:
npm run dev or yarn dev
Builds the electron app and runs this app.
npm run make or yarn make
Packages and distributes your application. It will create the out folder where your package will be located:
// Example for macOS out/
├── out/make/zip/darwin/x64/casdoor-electron-example-darwin-x64-1.0.0.zip
├── ...
└── out/casdoor-electron-example-darwin-x64/casdoor-electron-example.app/Contents/MacOS/casdoor-electron-example
Preview

Running the app opens a window. Click Login with Casdoor to open the Casdoor login page in your browser.

After sign-in, the app opens and shows your username.

Integration steps
1. Set the custom protocol
Register the casdoor custom protocol:
const protocol = "casdoor";
if (process.defaultApp) {
if (process.argv.length >= 2) {
app.setAsDefaultProtocolClient(protocol, process.execPath, [
path.resolve(process.argv[1]),
]);
}
} else {
app.setAsDefaultProtocolClient(protocol);
}
The browser can then open your app and pass the auth code via the protocol.