Documentation
¶
Overview ¶
Package npm is the npm registry credential provider: the access tokens npm has issued since 2021 (npm_…) and the UUID tokens before them.
Neither carries a checksum. The new format is matched on prefix, length and alphabet; a legacy UUID is only a token as the `_authToken` of an .npmrc line, since a bare UUID is anything. An .npmrc line also names the registry the token is for, which may be a private one: verification and revocation then go there instead of registry.npmjs.org. A token is revoked with itself, through the same endpoint `npm token revoke` uses.
Index ¶
- Constants
- type Provider
- func (p *Provider) AllowPrivateServers(allow bool)
- func (p *Provider) DryRunRevoke(ctx context.Context, tok detect.Token) error
- func (*Provider) Find(content []byte) []detect.Token
- func (*Provider) Kinds() []detect.KindInfo
- func (*Provider) LocalSources() detect.LocalSources
- func (*Provider) Name() string
- func (p *Provider) Revoke(ctx context.Context, tokens []detect.Token) error
- func (p *Provider) Verify(ctx context.Context, tok detect.Token) detect.Verification
Constants ¶
const ( // KindAccessToken is an access token of the current format (npm_). KindAccessToken detect.Kind = "npm-access-token" // KindLegacyToken is a UUID token from before 2021, only recognised as // the _authToken of an .npmrc line. KindLegacyToken detect.Kind = "npm-legacy-token" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Provider ¶
type Provider struct {
// RegistryURL is the public registry, https://registry.npmjs.org by
// default; a token found in an .npmrc line for another registry is
// checked against that one.
RegistryURL string
Client *http.Client
// Policy decides which private registries named in scanned content may
// be contacted.
Policy detect.ServerPolicy
}
Provider implements detect.Provider, detect.Revoker, detect.DryRunRevoker and detect.ServerVerifier for npm.
func (*Provider) AllowPrivateServers ¶
AllowPrivateServers implements detect.ServerVerifier.
func (*Provider) DryRunRevoke ¶
DryRunRevoke implements detect.DryRunRevoker: it authenticates with the token and looks it up in the account's list, exactly what Revoke does before deleting, and stops there. A registry that does not list the token (granular tokens are not listed) still accepts the deletion by value, so that is not a failure.
func (*Provider) Find ¶
Find implements detect.Provider. One substring pass finds the npm_ prefix; each candidate is checked for 36 alphanumerics standing on their own. One more pass finds `_authToken`, whose value is a token whatever its shape: a UUID there is a legacy token, and an npm_ token there learns which registry the line is for.
func (*Provider) Kinds ¶
Kinds implements detect.Provider. Both kinds revoke themselves through the registry's token API.
func (*Provider) LocalSources ¶
func (*Provider) LocalSources() detect.LocalSources
LocalSources implements detect.Provider: the user's .npmrc, and the environment variables the npm CLI, setup-node and CI templates read. The project's .npmrc in the working directory is checked for every provider.
func (*Provider) Revoke ¶
Revoke implements detect.Revoker through the registry's token API, one DELETE per token, authenticated with the token itself: the endpoint `npm token revoke` uses accepts the token value as the key. A registry that only takes the record's key gets a second DELETE with the key the token list shows for it. A 200 or 204 means the token is gone; the caller confirms with Verify.
func (*Provider) Verify ¶
Verify implements detect.Provider with one GET /-/whoami on the token's registry, the public one unless the .npmrc line named another. A live token then looks itself up in the account's token list to say whether it can publish; a granular token may not list tokens, which changes nothing about it being live. Only a 401 is revoked.