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 = var getRegistryUrl = // Get auth token and type for default `registry` set in `.npmrc`console // {token: 'someToken', type: 'Bearer'} // Get auth token for a specific registry URLconsole // 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 // Find the configured registry url for scope `@foobar`.// Falls back to the global registry if not defined.console // Use the npm config that is passed inconsole
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.