Running npm commands related to accessing GitHub registry when 2FA is set

Is it possible to use the --otp parameter to npm commands such as npm login to authenticate for GitHub Packages related actions? npm seems to provide for npmjs.org but I’m getting the following error even with --otp set:

> npm login --registry=https://npm.pkg.github.com/ --otp 123456
Username: sangeeth96
Password:
Email: (this IS public) me@example.com

npm ERR! code E401
npm ERR! 401 Unauthorized - PUT https://npm.pkg.github.com/-/user/org.couchdb.user:sangeeth96 - Error authenticating user: Must specify two-factor authentication OTP code.

Side note: please create a section for GitHub Packages related questions.

Hi @sangeeth96 ,

It should be not supported. There is no 2FA setting for package setting in github package registry ‘npm.pkg.github.com’, which is different with ‘npmjs.org’. Typically personal access token is used to authenticate to github package registry, please refer to official doc for more details.

If you would like to add this feature, according to the policy, please share your idea here where github product manager will take a review.

Thanks.

@sangeeth96 were you able to cope this?

You can set up github packages config even after 2FA is enabled, just don’t use your real password to login, but instead a new token.

  1. get token
    generate a token in https://github.com/settings/tokens with permissions of repo, write:packages, read:packages
  2. login with the above token as password when prompted, instead of the github login password
    npm login --registry=https://npm.pkg.github.com/