feat: 初始化SSO登录Electron应用
- 创建Electron主进程,加载SSO登录页面 - 配置electron-builder用于打包Mac/Windows/Linux - 添加证书忽略处理,支持自签名证书 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
node_modules/
|
||||
dist/
|
||||
.DS_Store
|
||||
*.log
|
||||
58
main.js
Normal file
58
main.js
Normal file
@@ -0,0 +1,58 @@
|
||||
const { app, BrowserWindow, session } = require('electron');
|
||||
const path = require('path');
|
||||
|
||||
// SSO登录URL
|
||||
const SSO_URL = 'https://yzsyhr.183.sc.cn/eassso/login?service=http%3A%2F%2Fyzsyhr.183.sc.cn%3A80%2Fshr%2F';
|
||||
|
||||
function createWindow() {
|
||||
const mainWindow = new BrowserWindow({
|
||||
width: 1280,
|
||||
height: 800,
|
||||
webPreferences: {
|
||||
nodeIntegration: false,
|
||||
contextIsolation: true,
|
||||
},
|
||||
title: 'SSO登录',
|
||||
icon: path.join(__dirname, 'icon.png'), // 可选图标
|
||||
});
|
||||
|
||||
// 忽略证书错误(如果有自签名证书)
|
||||
mainWindow.webContents.session.setCertificateVerifyProc((request, callback) => {
|
||||
callback(0); // 0 表示信任证书
|
||||
});
|
||||
|
||||
// 加载SSO页面
|
||||
mainWindow.loadURL(SSO_URL);
|
||||
|
||||
// 监听URL变化,登录成功后可以做后续处理
|
||||
mainWindow.webContents.on('did-navigate', (event, url) => {
|
||||
console.log('Navigated to:', url);
|
||||
|
||||
// 如果跳转到了目标应用,说明登录成功
|
||||
if (url.includes('/shr/') && !url.includes('eassso')) {
|
||||
console.log('Login successful, now at:', url);
|
||||
}
|
||||
});
|
||||
|
||||
// 打开开发者工具(调试用,正式版可注释掉)
|
||||
// mainWindow.webContents.openDevTools();
|
||||
}
|
||||
|
||||
// 忽略证书错误
|
||||
app.commandLine.appendSwitch('ignore-certificate-errors');
|
||||
|
||||
app.whenReady().then(() => {
|
||||
createWindow();
|
||||
|
||||
app.on('activate', () => {
|
||||
if (BrowserWindow.getAllWindows().length === 0) {
|
||||
createWindow();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
app.on('window-all-closed', () => {
|
||||
if (process.platform !== 'darwin') {
|
||||
app.quit();
|
||||
}
|
||||
});
|
||||
4998
package-lock.json
generated
Normal file
4998
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
53
package.json
Normal file
53
package.json
Normal file
@@ -0,0 +1,53 @@
|
||||
{
|
||||
"name": "sso-login-app",
|
||||
"version": "1.0.0",
|
||||
"description": "SSO登录客户端",
|
||||
"main": "main.js",
|
||||
"scripts": {
|
||||
"start": "electron .",
|
||||
"build": "electron-builder",
|
||||
"build:mac": "electron-builder --mac",
|
||||
"build:win": "electron-builder --win",
|
||||
"build:linux": "electron-builder --linux"
|
||||
},
|
||||
"build": {
|
||||
"appId": "com.company.sso-login",
|
||||
"productName": "SSO登录",
|
||||
"directories": {
|
||||
"output": "dist"
|
||||
},
|
||||
"mac": {
|
||||
"category": "public.app-category.business",
|
||||
"target": [
|
||||
"dmg",
|
||||
"zip"
|
||||
]
|
||||
},
|
||||
"win": {
|
||||
"target": [
|
||||
"nsis",
|
||||
"portable"
|
||||
]
|
||||
},
|
||||
"linux": {
|
||||
"target": [
|
||||
"AppImage",
|
||||
"deb"
|
||||
]
|
||||
},
|
||||
"nsis": {
|
||||
"oneClick": false,
|
||||
"allowToChangeInstallationDirectory": true
|
||||
}
|
||||
},
|
||||
"keywords": [
|
||||
"sso",
|
||||
"electron"
|
||||
],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"devDependencies": {
|
||||
"electron": "^39.2.7",
|
||||
"electron-builder": "^26.0.12"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user