Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose auth property for registry #171

Closed
lesteenman opened this issue Jun 27, 2024 · 9 comments · Fixed by #172
Closed

Expose auth property for registry #171

lesteenman opened this issue Jun 27, 2024 · 9 comments · Fixed by #172

Comments

@lesteenman
Copy link
Contributor

The plugin exposes the authToken property, which will be set during the publish command for the given registry:

      if (reg.authToken.isPresent) add("--//$repo:_authToken=${reg.authToken.get()}")

However, some registries require _auth rather than _authToken. The former is submitted as a basic auth string, the latter as a bearer token.

@mpetuska
Copy link
Owner

Happy to add support for _auth if you can link me to where it's documented.

@lesteenman
Copy link
Contributor Author

lesteenman commented Jun 28, 2024

This is where I got the info myself: https://docs.npmjs.com/cli/v10/configuring-npm/npmrc#auth-related-configuration

The settings _auth, _authToken, username and _password must all be scoped to a specific registry. This ensures that npm will never send credentials to the wrong host.

The full list is:

  • _auth (base64 authentication string)
  • _authToken (authentication token)
    ...

I can supply a PR if you want.

@mpetuska
Copy link
Owner

PR would be appreciated if you find the time.

@lesteenman
Copy link
Contributor Author

It seems like the CLI automatically generates the _auth from the username and _password if supplied, so I'm going with those instead. Working on the PR!

@lesteenman
Copy link
Contributor Author

Not sure what's going on, but when I use the username and _password properties from npm publish, the password gets sent to the registry incorrectly. As an example, sending "testusername" and "testpassword" results in the following authentication header:

  "authorization": "Basic dGVzdHVzZXJuYW1lOu+/ve+/vS3vv73vv70sworvv70=",

which decodes to garbage after the colon. This happens when I use NPM through the CLI or not. And given that I can't find enough documentation on it... I will implement it with _auth after all, and perform the base64 encoding manually in the plugin.

lesteenman added a commit to lesteenman/npm-publish that referenced this issue Jun 30, 2024
@lesteenman
Copy link
Contributor Author

It turns out NPM expects the _password property to be base64 encoded itself as well. I will add a comment with a reference if I can find any, but this doesn't seem to be documentated that well.

#172

@lesteenman
Copy link
Contributor Author

https://github.com/npm/cli/blob/3b8b11161ee2f88817dcc19b4770040d5bc73261/workspaces/arborist/README.md?plain=1#L42

this is the line that gave me the idea. However, it's not documentation of the CLI itself, but another NPM package it publishes from the same repository.

@lesteenman
Copy link
Contributor Author

Hi @mpetuska , any updates on a new release so we can use this?

@mpetuska
Copy link
Owner

3.5.0 is out with this. Apologies for the long delay, could not find time to sit with the project before holidays.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants