Search code examples
javascriptmacosnode-webkitnwjs

Get ANY kind of unique identifier in OSX under NW.JS


I am writing an application in NW.JS and need to be able to lock the application to specific machines. I would like to be able to programatically get any kind of string or value that is unique per machine.

I have tried using this https://www.npmjs.com/package/serial-number which seemed to work until I tried it on two machines where both machines generated the same serial number for the CPU. I have tried identifying via hardware MAC address and numerous other plugins that are all now labelled “depreciated”.

I have read that apple have locked down any unique identifiers on an OSX installation citing privacy concerns as the reason.

Is there any kind of approach that we can take now that I haven’t been able to find as of yet? I have heard of people randomly generating a string on first startup of their application and somehow putting that in the keychain but I really don’t understand how that would be done in NW.JS.

Does anybody know how to do this?


Solution

  • Here is a snippet from my working code (it is using https://github.com/scravy/node-macaddress):

        const macaddress = require('macaddress');
        macaddress.one((err, macAddress) => {
    
            let hardwareStr = JSON.stringify({
                os: os.platform(),
                hostname: os.hostname(),
                mac: macAddress || 'n/a'
            });
    
            let id = crypto.createHash('sha256')
                           .update(hardwareStr)
                           .digest('hex');
    
            // now id is machine-specific identifier without any sensitive information
    
        });
    

    Note: I cannot test it right now on Mac.