こんにちは、久々にnpm publishをしようと思ったら以下のエラーになりました。
npm notice Publishing to https://registry.npmjs.org/ with tag latest and default access
npm error code E403
npm error 403 403 Forbidden - PUT https://registry.npmjs.org/node-red-contrib-gyazo-api - Two-factor authentication or granular access token with bypass 2fa enabled is required to publish packages.
npm error 403 In most cases, you or one of your dependencies are requesting
npm error 403 a package version that is forbidden by your security policy, or
npm error 403 on a server you do not have access to.
12/9から2FAが強制へ。
以下機械翻訳です。
新規パッケージへのデフォルト2FA(新)
今週から、新規パッケージ公開における2FA強制がデフォルトとなります。新しいパッケージを作成すると、パッケージ設定で2FAが既定で有効になります。これにより、手動のセキュリティ設定を行わなくても、作成直後から保護されます。既存パッケージは現在の2FA設定が維持されます。
新しいセッションベース認証 ↗ 
本日より、npm loginを使用すると、長期間有効なトークンではなく2時間のセッショントークンが付与されます。セッションは2時間で自動的に期限切れとなり、公開を続けるには再認証が必要です。従来のトークンと異なり、セッショントークンはUIやCLIのトークン一覧には表示されません—裏側で認証済みセッションを維持します。セッション中、公開操作では2FAが強制され、セキュリティが一段と強化されます。
セキュリティ強化ですね。
2時間でセッションも切れるようになるとのこと。
対応手順
マイページからTwo-Factor Authenticationの箇所からEnable 2FAを選択
名前を付けてパスキーを登録します。最近のMacは指紋がいけて楽ですね。
iPhoneのQR読み込みは地味に面倒なので。。。
これで完了です。
再度Publishしてみる
$ npm publish
npm notice
npm notice 📦 node-red-contrib-gyazo-api@0.0.1
npm notice Tarball Contents
npm notice 11.4kB LICENSE
npm notice 206B README.md
npm notice 1.9kB nodes/get/get.html
npm notice 1.4kB nodes/get/get.js
npm notice 639B package.json
npm notice Tarball Details
npm notice name: node-red-contrib-gyazo-api
npm notice version: 0.0.1
npm notice filename: node-red-contrib-gyazo-api-0.0.1.tgz
npm notice package size: 5.7 kB
npm notice unpacked size: 15.5 kB
npm notice shasum: 7e69bd3062548eabb32588d4c691faf08448b3e2
npm notice integrity: sha512-zlz7s0bKfp8ko[...]J/KJv8rZ3SjEQ==
npm notice total files: 5
npm notice
npm notice Publishing to https://registry.npmjs.org/ with tag latest and default access
Authenticate your account at:
https://www.npmjs.com/auth/cli/7030a911-62d7-4fd8-8c4e-bbc719d2f40b
Press ENTER to open in the browser...
+ node-red-contrib-gyazo-api@0.0.1
いけました
パスキー追加しておこう
npmでパッケージ公開している人も、してない人も追加しておくのがオススメです。



