1

我使用 passport.js 将用户登录到我的应用程序。当护照完成身份验证时,我可以获得 github 访问令牌。然后我获取该访问令牌并尝试克隆用户的私人仓库。我没有使用个人访问令牌。有没有办法用从 passport.js 收到的 oauth 访问令牌克隆一个私人仓库?

护照登录:

authGithub: (req, res)=>{
    passport.authorize('github', {scope : ['user:email','repo'], accessType: 'offline', approvalPrompt: 'force'})(req, res)
  }

passport.use(new GitHubStrategy({
  clientID: config.custom.githubAuth.clientId,
  clientSecret: config.custom.githubAuth.clientSecret,
  callbackURL: config.custom.githubAuth.callbackUrl
},
  ((accessToken, refreshToken, params, profile, cb) => {
    profile.githubAccessToken = accessToken
    profile.githubRefreshToken = refreshToken
    return cb(null, profile);
  })
));

从那里,我在命令行上尝试了这些:

➜  Code git clone https://XXX@github.com/joncodo/react-analysis-sample
Cloning into 'react-analysis-sample'...
fatal: unable to look up XXX@github.com (port 9418) (nodename nor servname provided, or not known)
➜  Code git clone https://XXX:x-oauth-basic@github.com/joncodo/react-analysis-sample
Cloning into 'react-analysis-sample'...
fatal: unable to look up XXX:x-oauth-basic@github.com (port 9418) (nodename nor servname provided, or not known)
➜  Code git clone https://joncodo:XXX@github.com/joncodo/react-analysis-sample foo2
Cloning into 'foo2'...
fatal: unable to look up joncodo:XXX@github.com (port 9418) (nodename nor servname provided, or not known)

➜  Code mv ~/.ssh ~/.ssh_old
➜  Code git clone https://github.com/joncodo/react-analysis-sample foo
Cloning into 'foo'...
The authenticity of host 'github.com (140.82.112.3)' can't be established.
RSA key fingerprint is SHA256:XXX.
Are you sure you want to continue connecting (yes/no/[fingerprint])?
Host key verification failed.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
4

0 回答 0