2

I want to authenticate user with custom URL schema in which the link looks like this

appName://https://www.sitename.com/user-token

I implemented custom url successfully in info.plist file so that when clicking appName:// open my destop app.

My loadURL code looks like this in app.js

mainWindow.loadUrl('http://www.sitename.com/', {
        userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.52 Safari/537.36'
    });

Now how can i change the URL when the user clicks this

<a href="appName://https://www.sitename.com/user-token">Open App</a>

Any help?

vitr
  • 6,766
  • 8
  • 30
  • 50
Praveen
  • 21
  • 5

1 Answers1

1

You have to read the arguments in in Your Electron Model and use it to update the url. Probably you have to Base64-decode your wished url:

module.exports = new function () {
    var self = this,
        app = require('electron').app;

    // ...

    self.buildWindow = function (url) {
        app.on('ready', function () {

            // ...   

            self.applyExternalData(process.argv, url);
        }
    };

    self.applyExternalData = function (commandLine, currentUrl) {
        var newUrl;

        if (commandLine && commandLine[1] && commandLine[1].indexOf('appName://') === 0) {

            newUrl = commandLine[1].replace('appName://', '');
            self.mainWindow.webContents.executeJavaScript('window.document.location.href = ' + newUrl;);    

        }
    };
}
Darin Kolev
  • 3,401
  • 13
  • 31
  • 46