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

@node-cli-toolkit/oauth-cli

v1.0.2

Published

A Node utility that opens the `authorizationURL` (on the oauth server), starts an express server which listens for the redirect from the oauth server after the user logs in. Then the oauth2 library makes a request to the `tokenURL` and returns back the to

Downloads

73

Readme

OAuth CLI

A Node utility that opens the authorizationURL (on the oauth server), starts an express server which listens for the redirect from the oauth server after the user logs in. Then the oauth2 library makes a request to the tokenURL and returns back the token in the response. It resolves the promise of the OAuthCLI with the accessToken and refreshToken.

You can either use oauth2 directly (passing in a authorizationURL and tokenURL) or pass in any passport strategy

Installation

yarn add @node-cli-toolkit/oauth-cli

Usage

CLI Usage

Note that this package has a CLI avaialable where you can just pass in the options as arguments. See generate-oauth-token-cli for details.

Using Default Oauth2 Strategy

import oauthCLI from "@node-cli-toolkit/oauth-cli";

await oauthCLI({
  authorizationURL: "http://oauthprovider.com/oauth",
  tokenUrl: "http://oauthprovider.com/token",
  appKey: "key",
  appSecret: "secret"
});

Returns: The accessToken, refreshToken, user

{
  accessToken: "I_AM_THE_TOKEN",
  refreshToken: "REFRESH_TOKEN",
  user: {}
}

Using Custom Passport Strategy

import { Strategy as DropboxOAuth2Strategy } from "passport-dropbox-oauth2";
import oauthCLI from "@node-cli-toolkit/oauth-cli";

await oauthCLI({
  oauthStrategy: DropboxOAuth2Strategy,
  oauthStrategyOptions: {
    apiVersion: "2"
  },
  mutateUser: profile => ({
    userId: profile.id,
    email: profile.emails[0].value,
    name: {
      givenName: profile.name.givenName,
      familyName: profile.name.familyName,
      displayName: profile.displayName
    },
    // any other user details
    profile
  }),
  appSecret: "SECRET",
  appKey: "KEY"
});

Returns: The accessToken, refreshToken, user

{
  accessToken: "I_AM_THE_TOKEN",
  refreshToken: "REFRESH_TOKEN",
  user: {}
}

Save token to a file using a Token Identifier

This is great for prototyping. It saves your token to the file system in the /tmp folder with a unique token identifier. You can later retrieve it using getToken utility.

See @node/api-toolkit/save-token for more info

import oauthCLI from "@node-cli-toolkit/oauth-cli";

await oauthCLI({
  authorizationURL: "http://oauthprovider.com/oauth",
  tokenUrl: "http://oauthprovider.com/token",
  appKey: "key",
  appSecret: "secret",
  saveTokenToFile: true,
  tokenIdentifier: "NODE_CLI_TOOLKIT_OAUTH_TOKEN_JEST"
});

Returns: The accessToken, refreshToken, user

{
  accessToken: "I_AM_THE_TOKEN",
  refreshToken: "REFRESH_TOKEN",
  user: {}
}

Saves token to /tmp/NODE_CLI_TOOLKIT_OAUTH_TOKEN_JEST

You can retrieve using

import { getToken } from "@node-cli-toolkit/save-token";

const token = await getToken({
  tokenIdentifier: "NODE_CLI_TOOLKIT_OAUTH_TOKEN_JEST"
});

Save token to a file using a Token Identifier

This is great for prototyping. It saves your token to the file system in whatever file you choose. You can later retrieve it using getToken utility.

See @node/api-toolkit/save-token for more info

import oauthCLI from "@node-cli-toolkit/oauth-cli";

await oauthCLI({
  authorizationURL: "http://oauthprovider.com/oauth",
  tokenUrl: "http://oauthprovider.com/token",
  appKey: "key",
  appSecret: "secret",
  saveTokenToFile: true,
  tokenPath: "/tmp/node-api-toolkit-save-token-test-custom-file"
});

Returns: The accessToken, refreshToken, user

{
  accessToken: "I_AM_THE_TOKEN",
  refreshToken: "REFRESH_TOKEN",
  user: {}
}

Saves token to /tmp/node-api-toolkit-save-token-test-custom-file

You can retrieve using:

import { getToken } from "@node-cli-toolkit/save-token";

const token = await getToken({
  filePath: "/tmp/node-api-toolkit-save-token-test-custom-file"
});

Options

Required For All

  • appKey - Aka the clientID. This is the app key you get from creating your Oauth application
  • (ex for Dropbox: https://docs.gravityforms.com/creating-a-custom-dropbox-app/) (ex: 3u23809sd90239)
  • appSecret - Aka the clientSecret This is the app secret you get from creating your Oauth
  • application (ex: 3u23809sd90239)

Using Default Strategy

  • authorizationURL - Initial OAuth URL (example: https://www.dropbox.com/1/oauth2/authorize)
  • tokenUrl - The URL to fetch the token (example: https://api.dropbox.com/1/oauth2/token)
  • callbackURL - (optional) The URI of our local server (default: http://localhost:8888/redirect)

Passing IN a Custom Strategy

  • oauthStrategy - The Strategy constructor or require-able package name (ex: DropboxOAuth2Strategy or passport-dropbox-oauth2),

  • oauthStrategyOptions - The custom options you need pass to the strategy besides the appKey and appSecret. Example:

    {
       apiVersion: "2"
    }
  • mutateUser - (optional) - A parser for the user object (profile) you get back. Otherwise it just passes in the result

Saving Token to A File

  • saveTokenToFile - Should the token be saved to a file
  • tokenIdentifier - If saving to a file, what should be the unique token identifier. See @node/api-toolkit/save-token for more info
  • tokenPath - If saving to a file, what should be the filename (if not using a token identifier)

Tests and Todos

Everything in this package is tested thoroughly. You can also see planned features as part of the tests' todos. See tests directory.