1

我正在尝试通过 github 企业对我的 nodejs 客户端进行身份验证。nodejs 客户端在我自己的机器(localhost)中,github 企业托管在 ec2 机器中。github 企业有 https 的自签名 SSL 证书。我还为 localhost 实现了一个自签名 SSL 证书。我在我的 nodejs 客户端中使用了 passport-github2 来通过 github 企业进行身份验证。但是当我试图验证这个错误时,

{ InternalOAuthError: Failed to obtain access token
    at Strategy.OAuth2Strategy._createOAuthError (/home/sakibfuad/docker-or-visualizer/or-audit-app-server/node_modules/passport-oauth2/lib/strategy.js:408:17)
    at /home/sakibfuad/docker-or-visualizer/or-audit-app-server/node_modules/passport-oauth2/lib/strategy.js:175:45
    at /home/sakibfuad/docker-or-visualizer/or-audit-app-server/node_modules/oauth/lib/oauth2.js:191:18
    at ClientRequest.<anonymous> (/home/sakibfuad/docker-or-visualizer/or-audit-app-server/node_modules/oauth/lib/oauth2.js:162:5)
    at ClientRequest.emit (events.js:198:13)
    at ClientRequest.EventEmitter.emit (domain.js:448:20)
    at TLSSocket.socketErrorListener (_http_client.js:392:9)
    at TLSSocket.emit (events.js:198:13)
    at TLSSocket.EventEmitter.emit (domain.js:448:20)
    at emitErrorNT (internal/streams/destroy.js:91:8)
  name: 'InternalOAuthError',
  message: 'Failed to obtain access token',
  oauthError:
   { Error: self signed certificate
       at TLSSocket.onConnectSecure (_tls_wrap.js:1058:34)
       at TLSSocket.emit (events.js:198:13)
       at TLSSocket.EventEmitter.emit (domain.js:448:20)
       at TLSSocket._finishInit (_tls_wrap.js:636:8) code: 'DEPTH_ZERO_SELF_SIGNED_CERT' } }

我也尝试过使用 HTTP 协议进行身份验证(没有本地主机的自签名 SSL 证书),但它也不起作用。这个问题只出现在 github 企业。当我尝试使用https://github.com进行身份验证时,它工作正常。

这是我的 nodejs 客户端使用的代码片段

        passport.use(
                 new GithubStrategy(
                    {
                        clientID: githubCredentials.GITHUB_CLIENT_ID,
                        clientSecret: githubCredentials.GITHUB_CLIENT_SECRET,
                        callbackURL: `https://localhost:3002/login/github/return`,
                        scope: scopes.join(' '),
                        authorizationURL: `https://${github_enterprise_ip}/login/oauth/authorize`,
                        tokenURL: `https://${github_enterprise_ip}/login/oauth/access_token`,
                        userProfileURL: `https://${github_enterprise_ip}/api/v3/user`
                    },
                    function(token, tokenSecret, profile, cb) {
                      
                        return cb(null { profile: profile, token: token })
                    }
                )
            );

4

0 回答 0