Search code examples
electronauth0

How do I enable Auth0 logins in my Electron app now that Lock v10 is deprecated?


I have an Electron app that will talk to backend APIs secured to only accept Auth0 authorization tokens. Previously it was possible to use Auth0.js's Lock project, but Electron support ended at v10 and this was recently deprecated.

How else can I enable a login flow in my Electron app?


Solution

  • Try electron-auth0-login.

    You can download the package from NPM:

    # Installing electron-auth0-login
    npm install electron-auth0-login --save
    
    # Installing peer dependencies
    npm install request request-promise-native --save
    

    Initialising is simple. Just add the following to main process code:

    import ElectronAuth0Login from 'electron-auth0-login';
    
    const auth = new ElectronAuth0Login({
        // Get these from your Auth0 application console
        auth0Audience: 'https://api.mydomain.com',
        auth0ClientId: 'abc123ghiMyApp',
        auth0Domain: 'my-domain.eu.auth0.com',
        auth0Scopes: 'given_name profile'
    });
    

    Have a redirect URL whitelisted for https://{your-auth0-domain}/mobile.

    Now, when you want a token, call auth.getToken and electron-auth0-login will either return a token in memory (if valid), use a refresh token (if enabled) or kick off a new Auth0 login flow.

    Full details can be found on the project’s readme: https://github.com/jbreckmckye/electron-auth0-login