# auth0-node-login

> A library for authenticating users of a Node program with traditional browser-based Auth0 authorization flow. Recommended especially for CLIs.

Latest version **2.0.0** (published 2022-11-08) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install auth0-node-login
pnpm add auth0-node-login
yarn add auth0-node-login
bun add auth0-node-login
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2022-11-08 |
| First published | 2022-11-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Dependencies | 4 |
| Unpacked size | 16.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | ctjlewis |

## Links

- npm: https://www.npmjs.com/package/auth0-node-login
- npm.io page: https://npm.io/package/auth0-node-login

## Dependencies (4)

- [open](https://npm.io/package/open.md) ^8.4.0
- [jwt-decode](https://npm.io/package/jwt-decode.md) ^3.1.2
- [node-fetch](https://npm.io/package/node-fetch.md) ^3.2.10
- [debug-logging](https://npm.io/package/debug-logging.md) ^4.0.4

## Recent versions

- 2.0.0 (latest) — 2022-11-08
- 1.0.3 — 2022-11-08
- 1.0.1 — 2022-11-08
- 1.0.0 — 2022-11-07

## README

# Auth0 Node Login

A library for authenticating users of a Node program with traditional
browser-based Auth0 authorization flow. Recommended especially for CLIs.

### Prerequisites

This library uses a browser authorization code flow to authenticate a user. It
does this by starting a server locally, and setting the URL of that server as
the redirect location for the authorization process.

**You will need to add the client's redirect URL to <u>Applications >
[Application] > Allowed Callback URLs</u>.** The port can be overridden with the
`{ redirectPort }` config option, but by default, the callback URL is:

```
http://localhost:42069
```

### Usage

1. Create the Auth0 node client and export it for your program to use.
    ```ts
    // src/globs.ts

    export const AUTH0_CLIENT = new Auth0NodeClient({
      domain: "AUTH0_DOMAIN.us.auth0.com",
      redirectUri: "https://AUTH0_REDIRECT_URI",
      clientId: "AUTH0_CLIENT_ID",
      audience: "AUTH0_AUDIENCE",
      // redirectPort: 5555,
      // postLoginRedirect: "https://google.com",
    });
    ```

2. Import your client and use it to log in, log out, and make authenticated
   requests.

    ```ts
    // src/bin.ts
    import { AUTH0_CLIENT } from "./globs.ts";

    /** Log in using the browser. **/
    await AUTH0_CLIENT.login();

    // Later:

    /** Make authenticated requests. Uses `node-fetch` under the hood. */
    await AUTH0_CLIENT.fetch("http://my-api.com/endpoint", { /* ... */ });
    ```

![](demo.gif)

### Caching

Access tokens will automatically be cached on disk and cleared once they expire.
Calls to `login(config)` will resolve instantly when the cache is valid.

### External use

This library's internals are also all exposed if you wish to use them more
granularly in some other context - `authorizeWithBrowser()`, `cacheToken()`,
etc.

### Acknowledgements

Thanks to @altostra, @yevk, and @ShlomiAltostra for their work on
[`altostra-cli-login-auth0`](https://github.com/altostra/altostra-cli-login-auth0),
which was helpful for reference on browser opening.

### Disacknowledgments

Unthanks to the Auth0 team for making OSS authors write this multiple times
rather than writing it for developers to use. Auth0 PKCE is not easy to debug by
hand!

---
_Source: https://npm.io/package/auth0-node-login · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
