Skip to content

Commit

Permalink
Adds support for npm-notice during OTP requests
Browse files Browse the repository at this point in the history
  • Loading branch information
arcanis committed Mar 31, 2022
1 parent 751c895 commit 5b2ac04
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
9 changes: 8 additions & 1 deletion src/errors.js
Expand Up @@ -34,4 +34,11 @@ export class ResponseError extends Error {
responseCode: number;
}

export class OneTimePasswordError extends Error {}
export class OneTimePasswordError extends Error {
constructor(notice: string) {
super();
this.notice = notice;
}

notice: string;
}
4 changes: 4 additions & 0 deletions src/registries/npm-registry.js
Expand Up @@ -191,6 +191,10 @@ export default class NpmRegistry extends Registry {
}

this.reporter.info(this.reporter.lang('twoFactorAuthenticationEnabled'));
if (error.notice) {
this.reporter.info(error.notice);
}

this.otp = await getOneTimePassword(this.reporter);

this.requestManager.clearCache();
Expand Down
3 changes: 1 addition & 2 deletions src/util/request-manager.js
Expand Up @@ -440,9 +440,8 @@ export default class RequestManager {

if (res.statusCode === 401 && res.headers['www-authenticate']) {
const authMethods = res.headers['www-authenticate'].split(/,\s*/).map(s => s.toLowerCase());

if (authMethods.indexOf('otp') !== -1) {
reject(new OneTimePasswordError());
reject(new OneTimePasswordError(res.headers['npm-notice']));
return;
}
}
Expand Down

0 comments on commit 5b2ac04

Please sign in to comment.