-
Notifications
You must be signed in to change notification settings - Fork 3k
Conversation
lib/profile.js
Outdated
conf.auth = {basic: {username: creds.username, password: creds.password}} | ||
} else if (creds.auth) { | ||
const auth = Buffer.from(creds.auth, 'base64').toString().split(':', 2) | ||
conf.auth = {basic: {username: auth[0], passowrd: auth[1]}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: passowrd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ty!
lib/profile.js
Outdated
return profile.login(conf.auth.basic.username, conf.auth.basic.password, conf).then((result) => { | ||
if (!result.token) throw new Error("Your registry " + conf.registry + "does not seem to support bearer tokens. Bearer tokens are required for two-factor authentication") | ||
npm.config.setCredentialsByURI(conf.registry, {token: result.token}) | ||
return Bluebird.fromNode((cb) => npm.config.save('user', cb)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL about fromNode
!
lib/profile.js
Outdated
if (conf.auth.basic) { | ||
log.info('profile', 'Updating authentication to bearer token') | ||
return profile.login(conf.auth.basic.username, conf.auth.basic.password, conf).then((result) => { | ||
if (!result.token) throw new Error("Your registry " + conf.registry + "does not seem to support bearer tokens. Bearer tokens are required for two-factor authentication") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I note that it's possible that they enabled TFA in another session, & the reason that they cannot authenticate here is because of their already-active TFA status. Does profile.login
handle the OTP prompt in that case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, I see what you're saying…
So this flow only happens if you run npm profile enable-2fa
. So if you've enabled 2fa elsewhere but have a legacy auth on this account, I wouldn't expect you to be enabling 2fa here too? If you try you'll get an uncaught EOTP error. We could catch it here, but it's really a more general problem because sudenly every operation you do will ask for an OTP and I think it's far more likely that you'll get failures due to, for example, npm install
.
Tweaking the error handler to be more specific, that is, to tell folks to npm login
if they have bearer auth and just errored out due to EOTP (or E401 w/ no www-authenticate headers) would probably be good though.
8ece5e1
to
70fc403
Compare
70fc403
to
8a0e800
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🐑 LGTM
This adds legacy auth support to the new commands. (They thought they had it previously but weren't passing it along correctly.)
This also makes it so that enabling two-factor authentication upgrades your auth method to a bearer token. 2fa does not support basic authentication. If your registry does not support bearer authentication then we will now refuse to enable two-factor authentication.