Skip to content

Add NPM plugin - #422

Open
alondahari wants to merge 8 commits into
1Password:mainfrom
alondahari:main
Open

alondahari wants to merge 8 commits into
1Password:mainfrom
alondahari:main

Conversation

@alondahari

Copy link
Copy Markdown

Overview

This is a second attempt at creating an NPM plugin, following #168.

Currently, this plugin supports:

  • Importing existing project and user config files
  • Multiple registries and scopes

It does not yet support:

  • MFA
  • importing global and builtin config files

Type of change

  • Created a new plugin
  • Improved an existing plugin
  • Fixed a bug in an existing plugin
  • Improved contributor utilities or experience

How To Test

  • npm login to generate an .npmrc file if you don't have an existing one
  • init the plugin
  • remove your .npmrc file from your home folder
  • npm whoami

Changelog

Authenticate the NPM CLI using Touch ID and other unlock options with 1Password Shell Plugins.

This is the initial commit to handle integration with NPM, with the
official registry. After running the boiler plate I updated the relevant
fields, just enough to do manual testing of the basic use case (npm
install).

Still left to do:
- Parse existing .npmrc file
- Define when auth is needed
- testing

<!-- ps-id: d44814af-d6d4-4fd8-8dc4-62ed0ac06602 -->
Add a list of commands that don't require authentication. When running
those commands with the cli, the plugin will not try to fetch the token
from the vault.

I opted for a negative list of commands over a positive one since the
latter would end up being much longer, would need to be more complete,
and would probably need more updates with time, with newer npm versions.

<!-- ps-id: ec70313e-76dd-4aab-811d-196348b499ac -->
Update the access_token specfication to find the relevant .npmrc config
file and create the 1password secret from it when initializing the
plugin.

<!-- ps-id: e7ddf1fc-f911-475f-9b2c-5b43edd41471 -->
The .npmrc can live in the project root, as well as the home directory.

Decided to only support the per-project and per-user config files, since
the global and the builtin configs should not contain the auth config
probably.

Reference: https://docs.npmjs.com/cli/v10/configuring-npm/npmrc#global-config-file

<!-- ps-id: 362d7c8f-e1ad-4533-882f-e103b3d75caf -->
NPM packages can live in different registries, not just the official
one. This commit adds support for them by setting the env var according
to the right backend.

To support that, I had to use a temp file and not the env var
provisioner, since the key name would be different per registry.

I also added support for different scopes along the way.

I decided to separate the credentials instead of having a single line
ithe 1password vault, to allow users to configure their secrets more
easily.

<!-- ps-id: 7ec3e696-9c29-4354-bba5-ae4206bc871f -->
Let's support best practice by defaulting to the official npm registry
if the secret doesn't contain a host.
This will be useful when testing the access token
Add some tests around importing and provisioning the credentials.
@daniellockyer

Copy link
Copy Markdown

@mrjones2014 @RyanPrussin What else is needed to get this merged? I'd really like to avoid my npm token being leaked by malware, which is becoming an increasingly likely situation with recent ecosystem issues

@mrjones2014

Copy link
Copy Markdown
Member

Commits need to be signed and PR approved by 2 Go developers. I only really maintain the Nix stuff for the project and don't have any experience with Go or how the actual Go project is built.

@kasperisager

Copy link
Copy Markdown

Is there any chance of getting some traction on landing this? Providing a way to not have npm credentials sitting around on disk is incredibly valuable.

@dalldrit13 dalldrit13 mentioned this pull request Aug 8, 2026
1 of 4 tasks
@rr3khan rr3khan closed this Oct 12, 2026
@rr3khan rr3khan reopened this Oct 12, 2026
@github-actions

Copy link
Copy Markdown
Contributor

⚠️ This PR contains unsigned commits. To get your PR merged, please sign those commits (git rebase --exec 'git commit -S --amend --no-edit -n' @{upstream}) and force push them to this branch (git push --force-with-lease).

If you're new to commit signing, there are different ways to set it up:

Sign commits with gpg

Follow the steps below to set up commit signing with gpg:

  1. Generate a GPG key
  2. Add the GPG key to your GitHub account
  3. Configure git to use your GPG key for commit signing
Sign commits with ssh-agent

Follow the steps below to set up commit signing with ssh-agent:

  1. Generate an SSH key and add it to ssh-agent
  2. Add the SSH key to your GitHub account
  3. Configure git to use your SSH key for commit signing
Sign commits with 1Password

You can also sign commits using 1Password, which lets you sign commits with biometrics without the signing key leaving the local 1Password process.

Learn how to use 1Password to sign your commits.

Watch the demo

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

Successfully merging this pull request may close these issues.

5 participants