Skip to content

Support npm auth-and-writes 2FA setting #93

Open
@pvdlg

Description

@pvdlg

Follow-up to #92.

It should be possible to support npm auth-and-writes level of two-factor-authentication by generating the OTP on the CI with a tool like otplib.

Users would have to enable npm 2FA via command line and on the step where the QRCode is displayed, copy the secret key displayed below it (Something like Or enter code: XXXXXXXX....).
The secret would have to be added on the CI as a secured environment variable (e.g. NPM_2FA_SECRET).

The only constraint is that if 2FA is already enabled, there is no way to retrieve the secret key. So users would have to disable 2FA and re-enable it via CLI to obtain a new secret key.

Then the plugin would generate the OTP with:

const {authenticator} = require('otplib');

const otp =authenticator.generate(process.env.NPM_2FA_SECRET);

And call npm publish with the --otp option.

We would also need to implement #11 and make sure that if the auth-and-writes option is enabled the environment variable NPM_2FA_SECRET is set. Unfortunately it doesn't seems there is a way to verify if NPM_2FA_SECRET is correct, as all the npm command that requires an OTP are things that makes changes server side, so we can't use them to test.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions