5.1.0 • Published 1 year ago
registry-auth-token v5.1.0
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-tokenUsage
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')
// 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}))
// Use the npm config that is passed in
console.log(getAuthToken('//registry.foo.bar', {
npmrc: {
'registry': 'http://registry.foo.bar',
'//registry.foo.bar/:_authToken': 'qar'
}
}))
// 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/', {
'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:
undefinedSecurity
Please be careful when using this. Leaking your auth token is dangerous.
License
MIT © Espen Hovlandsdal
5.0.3
1 year ago
5.1.0
1 year ago
5.0.2
3 years ago
5.0.1
4 years ago
5.0.0
4 years ago
4.2.2
4 years ago
4.2.1
5 years ago
4.2.0
6 years ago
4.1.1
6 years ago
4.1.0
6 years ago
4.0.0
7 years ago
3.4.0
7 years ago
3.3.2
8 years ago
3.3.1
9 years ago
3.3.0
9 years ago
3.2.0
9 years ago
3.1.2
9 years ago
3.1.1
9 years ago
3.1.0
9 years ago
3.0.1
10 years ago
3.0.0
10 years ago
2.1.1
10 years ago
2.1.0
10 years ago
2.0.0
10 years ago
1.1.1
10 years ago
1.1.0
10 years ago
1.0.1
10 years ago