Skip to content

Commit 6e9f04b

Browse files
mkhlzkat
authored andcommitted
config: Search for authentication token defined by environment variable (#8)
As discussed on npm.community[1], the fact that npm registry authentication tokens cannot be defined using environment variables does not seem justified anymore. The restriction is caused by the config loader translating * all `_` to `-` * the whole variable name to lowercase while the credential checker expects a key ending in `:_authToken`. This change fixes the problem by having the credential checker try a key ending in `:-authtoken` after it tried `:_authToken`. Fixes: https://npm.community/t/233 Fixes: npm/npm#15565 PR-URL: #8 Credit: @mkhl Reviewed-By: @zkat
1 parent c3ab25f commit 6e9f04b

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

lib/config/get-credentials-by-uri.js

+6
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ function getCredentialsByURI (uri) {
3434
return c
3535
}
3636

37+
if (this.get(nerfed + ':-authtoken')) {
38+
c.token = this.get(nerfed + ':-authtoken')
39+
// the bearer token is enough, don't confuse things
40+
return c
41+
}
42+
3743
// Handle the old-style _auth=<base64> style for the default
3844
// registry, if set.
3945
var authDef = this.get('_auth')

0 commit comments

Comments
 (0)