Skip to content
This repository has been archived by the owner on Oct 23, 2022. It is now read-only.

feat: add support for token helper #2

Merged
merged 3 commits into from
Dec 25, 2021

Conversation

bruderstein
Copy link
Contributor

@bruderstein bruderstein commented Dec 20, 2021

Add support for token helper, a command line tool to obtain a token.

A token helper is an executable, set in the user's .npmrc which
outputs an auth token. This can be used in situations where the
authToken is not a constant value, but is something that refreshes
regularly, where a script or other tool can use an existing refresh
token to obtain a new access token.

The configuration for the path to the helper must be an absolute path,
with no arguments. In order to be secure, it is only permitted to set
this value in the user .npmrc, otherwise a project could place a value
in a project local .npmrc and run arbitrary executables. For this
reason, the userConfig is added as a third parameter to the
function, to enable only allowing this value from that .npmrc.

A similar feature is available in many similar tools. The implementation
here is modelled after the vault (vaultproject.io) implementation

I have a PR ready to go for pnpm itself to use this. I'll raise that shortly, even though that will rely on this, and require the new version of this package to be published.

Add support for token helper, a command line tool to obtain a token.

A token helper is an executable, set in the user's `.npmrc` which
outputs an auth token. This can be used in situations where the
`authToken` is not a constant value, but is something that refreshes
regularly, where a script or other tool can use an existing refresh
token to obtain a new access token.

The configuration for the path to the helper must be an absolute path,
with no arguments. In order to be secure, it is _only_ permitted to set
this value in the user `.npmrc`, otherwise a project could place a value
in a project local `.npmrc` and run arbitrary executables. For this
reason, the userConfig is added as a third parameter to the
function, to enable only allowing this value from that `.npmrc`.

A similar feature is available in many similar tools. The implementation
here is modelled after the `vault` (vaultproject.io) implementation
- https://github.com/hashicorp/vault/blob/main/command/token/helper_external.go
index.js Outdated Show resolved Hide resolved
test-exec.js Show resolved Hide resolved
bruderstein and others added 2 commits December 23, 2021 21:41
The windows tests now run a batch file which outputs the token
or exits with an exit code.
@bruderstein
Copy link
Contributor Author

@zkochan applied the changes from the comments, tested on windows, linux + mac.

I tried to make the OS dependent parts such that coverage would not be affected, so it's still at 100% coverage.

@zkochan zkochan merged commit 9d8814b into pnpm:master Dec 25, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants