【问题标题】:Electron BrowserWindow/BrowserView loadURL with a client certificate带有客户端证书的 Electron BrowserWindow/BrowserView loadURL
【发布时间】:2022-07-13 08:14:29
【问题描述】:

我的 Electron 桌面应用程序正在使用 BrowserWindow.loadURL、BrowserView.loadURL 或 BrowserWindow.webContents.loadURL 方法在渲染器进程中访问 https 网站。但是目标网站需要验证我的客户证书。如何使用客户端证书提出请求?我有一个 .crt 文件、一个 .key 文件和两个 CA 证书文件。

我尝试了“select-client-certificate”事件,但没有触发。我也试过 app.commandLine.appendSwitch('client-certificate', ) 但它也没有用。

【问题讨论】:

    标签: authentication electron client-certificates


    【解决方案1】:

    在电子应用程序上尝试select-client-certificate 时没有成功,但我能够通过执行以下操作使其工作。另一件重要的事情是 select-client-certificate 只有在您尝试在典型浏览器(Safari、Chrome、Edge 等)中执行此操作时才会被调用,它会显示一个选择证书的弹出窗口。

    const child = new BrowserWindow({
        ...
    });
    
    child.webContents.on('select-client-certificate', (event: Event,
        url: string,
        certificateList: Certificate[],
        callback: (certificate: Certificate) => void) => {
        console.log('select-client-certificate url', url)
        console.log('select-client-certificate list', certificateList)
        // IMPORTANT: to prevent the default.
        event.preventDefault()
    
        // Selects the first certificate in the list of available.
        callback(certificateList[0])
    });
    
    // IMPORTANT: This is after .on('select-client-certificate')
    await child.loadURL(url);
    

    【讨论】:

      猜你喜欢
      • 2011-12-10
      • 2013-02-25
      • 2023-03-23
      • 1970-01-01
      • 2020-03-24
      • 2016-03-09
      • 2013-03-13
      • 2013-04-27
      • 2012-07-28
      相关资源
      最近更新 更多