Skip to content

Add npm and pnpm support - #658

Open
dalldrit13 wants to merge 1 commit into
1Password:mainfrom
dalldrit13:npm-plugin
Open

Add npm and pnpm support#658
dalldrit13 wants to merge 1 commit into
1Password:mainfrom
dalldrit13:npm-plugin

Conversation

@dalldrit13

Copy link
Copy Markdown

Overview

This change introduces a 1Password plugin supporting npm and pnpm. Currently both these systems default is to store credentials on disk in plaintext. 1Password to the rescue!

Type of change

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

Related Issue(s)

Didn't see any related issues however similar PR here that looks to be stale from ~2 years ago.

How To Test

Once built run op plugin init npm or op plugin init pnpm. Follow the steps and then you can verify functionality with npm whoami or pnpm whoami.

Note: You do need an npm account for testing this.

File import should work if you've run npm login or pnpm login as these generate the plaintext file the plugin looks for. You can also generate granular access tokens in npm and paste those in the paste flow

Changelog

Authenticate with npm (or pnpm) using the newly supported plugins

Some additional notes for the technical writing team in the case this gets accepted and published.

  • If a user is importing from a file they should probably be advised to remove the plaintext file once they've configured the plugin, (not strictly necessary functionally but kinda the whole idea of using the plugin is not having plaintext api keys lying about and the plugin ecosystem doesn't seem to provide any way of prompting the removal of these files at the CLI)
  • Running npm login or pnpm login after configuring the plugin will not update your token in 1P but rather it will rewrite the token back into a plaintext file. npm will continue to use what's in 1P, and pnpm puts higher precedence on auth.ini so that will override our 1P token. I could not think of a clean way to manage this nor did I see an existing pattern in any other plugin. For something like gh, the CLI itself handles this case
    gh auth login 
    ? Where do you use GitHub? GitHub.com
    The value of the GH_TOKEN environment variable is being used for authentication.
    To have GitHub CLI store credentials instead, first clear the value from the environment.
    There should probably be guidance around this quirk and encourage users to create granular tokens in the web UI instead of the login commands. It's also worth noting in the past year npm has cranked down their default token expiry on tokens created using npm login to I believe 1 hour, so users running this often would continually hit this limitation.

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.

1 participant