node/deps/npm/node_modules/registry-auth-token
Ruy Adorno b2e1a01516
deps: upgrade npm to 6.14.4
PR-URL: https://github.com/nodejs/node/pull/32495
Reviewed-By: Myles Borins <myles.borins@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
2020-03-26 13:28:08 -04:00
..
test deps: upgrade npm to 6.14.4 2020-03-26 13:28:08 -04:00
.npmignore deps: upgrade npm to 6.14.4 2020-03-26 13:28:08 -04:00
base64.js deps: upgrade npm to 6.1.0 2018-05-24 23:24:45 -07:00
CHANGELOG.md deps: upgrade npm to 6.14.4 2020-03-26 13:28:08 -04:00
index.js deps: upgrade npm to 6.14.4 2020-03-26 13:28:08 -04:00
LICENSE deps: upgrade npm to 6.1.0 2018-05-24 23:24:45 -07:00
package.json deps: upgrade npm to 6.14.4 2020-03-26 13:28:08 -04:00
README.md deps: upgrade npm to 6.1.0 2018-05-24 23:24:45 -07:00
registry-url.js deps: upgrade npm to 6.1.0 2018-05-24 23:24:45 -07:00
yarn.lock deps: upgrade npm to 6.14.4 2020-03-26 13:28:08 -04:00

registry-auth-token

npm versionBuild Status

Get the auth token set for an npm registry from .npmrc. Also allows fetching the configured registry URL for a given npm scope.

Installing

npm install --save registry-auth-token

Usage

Returns an object containing token and type, or undefined if no token can be found. type can be either Bearer or Basic.

var getAuthToken = require('registry-auth-token')
var getRegistryUrl = require('registry-auth-token/registry-url')

// Get auth token and type for default `registry` set in `.npmrc`
console.log(getAuthToken()) // {token: 'someToken', type: 'Bearer'}

// Get auth token for a specific registry URL
console.log(getAuthToken('//registry.foo.bar'))

// Find the registry auth token for a given URL (with deep path):
// If registry is at `//some.host/registry`
// URL passed is `//some.host/registry/deep/path`
// Will find token the closest matching path; `//some.host/registry`
console.log(getAuthToken('//some.host/registry/deep/path', {recursive: true}))

// Find the configured registry url for scope `@foobar`.
// Falls back to the global registry if not defined.
console.log(getRegistryUrl('@foobar'))

// Use the npm config that is passed in
console.log(getRegistryUrl('http://registry.foobar.eu/', {
  npmrc: {
    'registry': 'http://registry.foobar.eu/',
    '//registry.foobar.eu/:_authToken': 'qar'
  }
}))

Return value

// If auth info can be found:
{token: 'someToken', type: 'Bearer'}

// Or:
{token: 'someOtherToken', type: 'Basic'}

// Or, if nothing is found:
undefined

Security

Please be careful when using this. Leaking your auth token is dangerous.

License

MIT-licensed. See LICENSE.