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

Yarn publish command not reading password from .yarnrc #3932

Open
bchoddny opened this issue Jul 13, 2017 · 7 comments
Open

Yarn publish command not reading password from .yarnrc #3932

bchoddny opened this issue Jul 13, 2017 · 7 comments

Comments

@bchoddny
Copy link

Do you want to request a feature or report a bug?
Can yarn publish step read password from .yarnrc file? I would like to publish my package as part of my continuous integration process
What is the current behavior?
yarn doesn't read password from .yarnrc file, but it does reads username. Is there any other alternative since the continuous integration process cannot work with interaction.

What is the expected behavior?
Read credentials from yarnrc file
Please mention your node.js, yarn and operating system version.
yarn 0.27.2
node 6.9.4
mac 10.11.3

@Daniel15
Copy link
Member

Looking at the code, it seems like _username and _password should work:

// Check for bearer token.
const authToken = this.getRegistryOrGlobalOption(registry, '_authToken');
if (authToken) {
return `Bearer ${String(authToken)}`;
}
// Check for basic auth token.
const auth = this.getRegistryOrGlobalOption(registry, '_auth');
if (auth) {
return `Basic ${String(auth)}`;
}
// Check for basic username/password auth.
const username = this.getRegistryOrGlobalOption(registry, 'username');
const password = this.getRegistryOrGlobalOption(registry, '_password');
if (username && password) {
const pw = new Buffer(String(password), 'base64').toString();
return 'Basic ' + new Buffer(String(username) + ':' + pw).toString('base64');
}
}

You could try an auth token in _authToken instead. Log in to npm or Yarn then copy the auth token it saves to the .yarnrc or .npmrc.

@bchoddny
Copy link
Author

Either password or _password didn't work.

How do I get the authentication token, can you please provide me some steps. I tried the command:
"yarn login", but it didn't provide any authentication token?

@Daniel15
Copy link
Member

Daniel15 commented Jul 16, 2017

Try npm login, enter your username and password, and then look in ~/.npmrc. It should have a line like this:

//registry.npmjs.org/:_authToken=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx

Update your CI environment to write this to ~/.npmrc. I don't think yarn login does auth the same way, but it does support npm auth tokens so this should work with Yarn too. Using an auth token is more secure as it does not expose your password (so there's no possibility for your password to leak)

@gutenye
Copy link

gutenye commented Jul 25, 2017

I have same problem, after add _authToken to ~/.yarnrc got this error:

error An unexpected error occurred: "Unknown token 8:1 in /Users/guten/.yarnrc".

@akloeber
Copy link

akloeber commented May 6, 2018

@gutenye I ran into this problem as well. Because of the underscore it needs to be defined with surrounding quotes like that:

"_authToken" <TOKEN>

Or you can set it via yarn config set _authToken <TOKEN> which does it for you.

@akloeber
Copy link

akloeber commented May 6, 2018

I have the same problem as well (_authToken in this case).

After doing some debugging it looks like NpmRegistry#config only contains values from .npmrc when NpmRegistry#getAuth is called. So, it only works if _authToken, _auth, _password etc. are defined in .npmrc.

Nevertheless at the end of YarnRegistry#loadConfig the config object of that instance is populated as expected but there is also another instance of NpmRegistry which is used in this yarn publish case. I have no idea if this is the intended behavior.

This has been reproduced with latest yarn v1.6.0.

@giridhara-avadhani
Copy link

@akloeber Thanks for the ""(double quotes) solution. I was breaking my head for like 8 hours. Adding the double quotes around _auth fixed it :)

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

No branches or pull requests

5 participants