octokit-rest node-js:授权用户名和密码出现 "Token passed to createTokenAuth is not a string" 错误

octokit-rest node-js: authorising username and password gets "Token passed to createTokenAuth is not a string" error

编辑:尽管试图让它工作 5 个多小时,但我只是看到我在下面描述的方法实际上已被弃用。任何落入我所设陷阱的人都应该改用访问令牌 (https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token) and then (https://octokit.github.io/rest.js/v18#authentication)

当使用带有节点 js 的 octokit rest 包来验证 github 用户时,指导似乎非常简单

const { Octokit } = require('@octokit/rest');

const octokit = new Octokit({
 auth: {
   username: this_username,
   password: this_password,
   on2fa () {
    return prompt('Enter code')
   }
  }
});

然而,当我在节点 js 中 运行 时(已将 this_username 和 this_password 设置为我的 github 用户名和密码),我收到以下错误:

Uncaught Error: [@octokit/auth-token] Token passed to createTokenAuth is not a string
    at Object.createTokenAuth (D:\github\sos\collector-dev\web\node_modules\@octokit\auth-token\dist-node\index.js:39:11)
    at new Octokit (D:\github\sos\collector-dev\web\node_modules\@octokit\core\dist-node\index.js:115:32)
    at new _a (D:\github\sos\collector-dev\web\node_modules\@octokit\core\dist-node\index.js:167:30)
    at new OctokitWithDefaults (D:\github\sos\collector-dev\web\node_modules\@octokit\core\dist-node\index.js:147:9)

有趣的是,当我故意输入错误的密码时,我得到了同样的错误信息。

关于我错过的任何步骤有什么想法吗?还是我误解了 octokit 要求的用户名和密码?

如您所述,这是一种已弃用的方法,不建议使用。尽管如此,我还是发现了一个关于如何让它工作的讨论 https://github.com/octokit/rest.js/discussions/1881#discussioncomment-81110(直到 Github 决定绝对关闭):

const octokit = new Octokit({
  authStrategy: createBasicAuth,
  auth: {
    username: this_username,
    password: this_password
  }
});