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
.
var getAuthToken = require('registry-auth-token')
var 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(getRegistryUrl('@foobar'))
console.log(getRegistryUrl('http://registry.foobar.eu/', {
npmrc: {
'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-licensed. See LICENSE.