13

I am using electron forge for building and packaging my electron app.

How can I code sign my app (using electron forge) for windows and mac?

Electrong-forge: https://github.com/electron-userland/electron-forge

galusben
  • 5,948
  • 6
  • 33
  • 52
  • I could not sign using electron forge. I have ended up using electron builder. https://github.com/electron-userland/electron-builder – galusben May 09 '18 at 06:03
  • 1
    Electron-forge uses electron-packager, so you can pass the appropriate configuration to the electron-forge command to get signing. See this link https://electronjs.org/docs/tutorial/code-signing#signing-macos-builds – wkhatch Sep 09 '18 at 18:32

3 Answers3

9

EDIT: see https://stackoverflow.com/a/58665415/2165342 bellow. electronPackagerConfig is now packagerConfig

Use packagerConfig key in your package.json.

Electron Forge uses Electron Packager under the hood and allows you to set the Electron Packager configuration in your package.json.

Here's an extract of what mine looks like in order to sign our packaged application file:

package.json

{ 
  "config": {
    "forge": {
      "packagerConfig": {
        "osxSign": {
          "identity": "Developer ID Application: Joshua Pinter (<your_key_code>)"
        }
      }
    }
  }
}

You can see that all the Electron Packager configurations can be put under the packagerConfig key.

NOTE: In older versions of Electron Forge, this was called electronPackagerConfig instead of packagerConfig.

galusben
  • 5,948
  • 6
  • 33
  • 52
Joshua Pinter
  • 45,245
  • 23
  • 243
  • 245
  • 1
    Thanks for this addition. It would be great to have this documented on the official github repo. They might have added the docs by now. – galusben Jan 15 '19 at 18:15
  • @gba Docs are still pretty sparse, unfortunately. – Joshua Pinter Jan 16 '19 at 04:38
  • 2
    To get the identity, you can type in the following command from the command prompt: ``` security find-identity -p codesigning -v ``` – Bing Feb 07 '20 at 21:02
  • If you are doing this via SSH, remember to `security unlock-keychain` before you run `yarn make`, as it will give you a very cryptic error: WARNING: code sign failed; please retry manually.... but not explain that it is simply the keychain being locked. You can of course run it in the Terminal.app and it will prompt you to unlock it, but OSX can't or won't prompt you remotely. – Grizly Feb 25 '22 at 06:25
2

electronPackagerConfig is now packagerConfig, e.g.:

{ 
  "config": {
    "forge": {
      "packagerConfig": {
        "osxSign": {
          "identity": "Developer ID Application: Company (id)"
        }
      }
    }
  }
}

Ed McManus
  • 7,088
  • 2
  • 25
  • 17
  • Thanks a lot, I was wondering why the accepted answer was not working! – Oscar Franco Feb 17 '20 at 16:23
  • when I open the app after signing with electron-forge, it crashes. Any idea why is this happening ? – Zohra Gadiwala May 07 '20 at 16:24
  • No but you could check Console (on MacOS) to see if there’s log output from the process. Or try running the app binary directly from Terminal to see if there are any error messages. – Ed McManus May 08 '20 at 17:29
0

Only signing the electron app won't let the app work in production, as GateKeeper will not allow the app to open. You need to sign the application and then perform notarization. Here is how you can do that with electron forge.

"packagerConfig": {
  "icon": "./resources/icon",
  "osxSign": {
    "identity": "Developer ID Application: Kiran Maniya (R8A8NS532)"
  },
  "osxNotarize": {
    "tool": "notarytool",
    "appleApiKey": "./signing/AuthKey_R8A8NS532.p8",
    "appleApiKeyId": "R8A8NS532",
    "appleApiIssuer": "30651f9c-0046-4d6a-aba3-db72ff6c32ef"
  }
},

You can retrieve the identity name by running the command given below. Remember, The Developer ID Installer certificate is for apps distributed to the Mac App Store and Developer ID Application certificate is for apps distributed outside the Mac App Store.

security find-identity -p codesigning -v
Kiran Maniya
  • 8,453
  • 9
  • 58
  • 81