Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Error Launching App" After clicking the login button #3

Open
Nantris opened this issue Mar 22, 2017 · 13 comments
Open

"Error Launching App" After clicking the login button #3

Nantris opened this issue Mar 22, 2017 · 13 comments

Comments

@Nantris
Copy link

Nantris commented Mar 22, 2017

Thanks for putting together these demos.

When I launch the Electron demo and click login I get the following:

image

and then after clicking to open the URL:

image

Any thoughts? Thanks again!

@darkyen
Copy link
Owner

darkyen commented Mar 22, 2017

You'll to create an API in Dashboard > APIs and then pass the audience as the API_IDENTIFIER.

@Nantris
Copy link
Author

Nantris commented Mar 22, 2017

But this is using the example values, which it looks like should work out of box?

@darkyen
Copy link
Owner

darkyen commented Mar 22, 2017

Change it to https:// :)

@Nantris
Copy link
Author

Nantris commented Mar 22, 2017

I will try that. Thanks very much for the demos and the very speedy responses!

@Nantris
Copy link
Author

Nantris commented Mar 22, 2017

That definitely got my to the login screen. Now I get a very similar issue on the callback though.

image

I take it I just need to go through the code and change all the HTTP to HTTPS ?

@darkyen
Copy link
Owner

darkyen commented Mar 22, 2017

You should initialize your own keys at this point. I left the .env in there by accident. This error is probably happening as electron is not handling the url properly. Can you check if the .on('open-url') ever called?

@Nantris
Copy link
Author

Nantris commented Mar 22, 2017

It doesn't seem to be called. I'm not seeing the console.log("Open url called with", url); statement printed in the terminal that I run npm run electron from.

@darkyen
Copy link
Owner

darkyen commented Mar 22, 2017

Hmm, this seems like an electron issue, can you check if the app is running in single instance mode? Please refer to the electron docs for more.

@Nantris
Copy link
Author

Nantris commented Mar 25, 2017

It turns out app.setAsDefaultProtocolClient(env.packageIdentifier); will only run in a packaged application, so I packaged it up and modified app.makeSingleInstance

I'm now running that, but it returns me to the application and does nothing.

I just learned that 'open-url' only works on MacOS right now. I'm guessing that's the environment you code in? No dice on Window unfortunately, but I see there is some work going on towards fixing that issue: electron/electron#8052

@darkyen
Copy link
Owner

darkyen commented Mar 28, 2017

@slapbox In that case I recommend you take good old express-js and create a simple express server in your service which handles the callback. You can then skip singleInstance and open-url altogether even on OS X. As a bonus you can also render a screen asking the user to close the browser :D

@Nantris
Copy link
Author

Nantris commented Mar 28, 2017

@darkyen Thanks very much for the advice. This is not an option that ever would have occurred to me. I'll certainly look into it.

@b4dnewz
Copy link

b4dnewz commented Dec 2, 2017

I've the same issue:

Could not find any application or handler for app-name://tenant/electron/app-name/callback?code=xxx

on linux but I think is a known problem of electron.setAsDefaultProtocolClient do you have any suggestion how to fix it?

I'm struggling a lot trying to setup auth0 on electron.. I can't make it working I've also tried this method I describe in this other issue that lead me here.

@paxti
Copy link

paxti commented Feb 4, 2018

Well after some struggle I think I've found a solution at least for Windows. As it was mentioned above setAsDefaultProtocolClient works only for the packaged apps. However at least for windows setAsDefaultProtocolClient has two optional parameters that can be used to set Electron executable for dev environment

app.setAsDefaultProtocolClient(env.packageIdentifier, process.execPath, [path.resolve(process.argv[1])])

or something like this as a more 'finished' solution

if (process.defaultApp) {
  if (process.argv.length >= 2) {
    app.setAsDefaultProtocolClient(env.packageIdentifier, process.execPath, [path.resolve(process.argv[1])])
  }
} else {
  app.setAsDefaultProtocolClient(env.packageIdentifier)
}

This will fix the problem with 'Unable to find Electron app' but electron will create a new window after browser attempt to open Electron app. To make sure you have only one window use app.makeSingleInstance it has a callback that gets all arguments so it's possible to intercept creation of the new window and what is more important use args to get callback URL. Something like this should do the trick

const isSecondInstance = app.makeSingleInstance((args, _) => {

  mainWindow.webContents.executeJavaScript(`
    window.handleOpenURL('${args[2]}');
  `);

  if (mainWindow) {
    if (mainWindow.isMinimized()) mainWindow.restore()
      mainWindow.focus()
    }
  }
)   

if (isSecondInstance) {
    app.quit()
}

If interested this is the whole index.js that worked for me.

P.S. I am using Electron v 1.7.10. Not tested on Mac

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants