npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

jom-electron-auth0-login

v1.0.1

Published

Provides Auth0 authentication services for your Electron.js application

Downloads

6

Readme

Electron Auth0 Login

Enables Auth0 login within your Electron application, using proof-key-for-code-exchange (PKCE)

  • 🔒 Uses the industry-standard PKCE flow, as recommended by Auth0 for native apps
  • 🎿 Easy setup and a simple promise-based API
  • 🔄 Supports refresh tokens for 'login once' functionality
  • 💪 TypeScript support
  • 🌍 Provided under MIT license

🔑 What exactly does this do?

When asked for an auth token, this library will try the following:

  1. If you have a valid token in memory, and won't expire in the next 60 seconds, we return it
  2. If you have a refresh token, we exchange it for a new token
  3. If you have no refresh token (or have refresh tokens disabled), we open a new window with the Auth0 login page and begin a PKCE flow.

Discover more features in the API docs.

📖 Docs

New version!

💥 Version 2 now out! New features include:

  • easier setup with no need for peer dependencies
  • support for non-Keytar refresh token libraries
  • support for future extensibility

Problems?

If you're having problems with the latest v2 release, try npm install [email protected].

Docs for the old release are here.

🚀 Quick start guide: getting auth tokens

Install using NPM or Yarn:

# NPM
npm install electron-auth0-login

# Yarn
yarn add electron-auth0-login

🚨 This library expects a peerDependency of Electron 7+

Set up an application in the Auth0 console:

  • create a native application (not machine-to-machine)
  • set up an "Allowed callback URL" for https://{your auth0 domain}/mobile

Create a file called auth.ts/auth.js:

// For JS use require() instead
import { auth0Login } from 'electron-auth0-login';

// Only import this directly into your main process
// For the rendering process, use electron.remote.require()

export default auth0Login({
  // Get these values from your Auth0 application console
  auth0: {
    audience: 'url',
    clientId: 'long base64 string',
    domain: 'url',
    scopes: 'these will be custom to your application'
 }
});

Getting a token

In your main process, you can just import the library directly:

// In your main.ts file, or a file imported by main.ts
// For JS use require() instead
import { getToken } from './auth';

async function example() {
  // Example: using a bearer token
  const token = await getToken();
  apiCall({
    headers: {
      Authorization: `Bearer ${token}`
    }
  });
}

In the rendering process, you need to use electron.remote.require:

// For JS use require() instead
import { remote } from 'electron';

const { getToken } = remote.require('./auth'); // depending where you put 'auth.ts'

async function example() {
  // Example: using a bearer token
  const token = await getToken();
  apiCall({
    headers: {
      Authorization: `Bearer ${token}`
    }
  });
}

For more details, including advanced options and refresh tokens, take a look at the [Setup guide].

Discover other methods you can call in the [API guide].

🛠 Issues / contributions

Feel free to open an issue or pull request. Try to make these as detailed as possible: the more info, the easier it is to help. Example code is always good.

If you want to develop this library, just clone and npm install. To grok the general layout and architecture of the project, read https://github.com/jbreckmckye/node-typescript-architecture.

Check out the electron-login-test project too, which will allow you to test your changes manually in an example Electron app.

📜 General details

This library is made available under the MIT license: see LICENSE file.

It was originally inspired by @adeperio's Electron PKCE example: https://gist.github.com/adeperio/73ce6680d4b80b45e624ab62bacfbdca

Copyright 2018-2021 Jimmy Breck-McKye.