registry-auth-token
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
.
const getAuthToken = require('registry-auth-token')
const getRegistryUrl = require('registry-auth-token/registry-url')
console.log(getAuthToken())
console.log(getAuthToken('//registry.foo.bar'))
console.log(getAuthToken('//some.host/registry/deep/path', {recursive: true}))
console.log(getAuthToken('//registry.foo.bar', {
npmrc: {
'registry': 'http://registry.foo.bar',
'//registry.foo.bar/:_authToken': 'qar'
}
}))
console.log(getRegistryUrl('@foobar'))
console.log(getRegistryUrl('http://registry.foobar.eu/', {
'registry': 'http://registry.foobar.eu/',
'//registry.foobar.eu/:_authToken': 'qar'
}))
Return value
{token: 'someToken', type: 'Bearer'}
{token: 'someOtherToken', type: 'Basic'}
undefined
Security
Please be careful when using this. Leaking your auth token is dangerous.
License
MIT © Espen Hovlandsdal