How can I authenticate my localhost nodejs client by github enterprise (hosted in an ec2) using passport-github2?

191 Views Asked by At

I am trying to authenticate my nodejs client by the github enterprise. The nodejs client is in my own machine(localhost) and the github enterprise is hosted in an ec2 machine. The github enterprise has a self-signed SSL certificate for https. I have also implemented a self signed SSL certificate for localhost. I have used passport-github2 in my nodejs client for authentication via github enterprise. But when I am trying to authenticate this error is thrown,

{ 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' } }

I have also tried to authenticate using HTTP protocol (without the self-signed SSL certificate for localhost) but it did not work also. This problem only occurs for github enterprise. When I try to authenticate using https://github.com it works fine.

Here is the code snippet used by my nodejs client

        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 })
                    }
                )
            );

0

There are 0 best solutions below