Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Github Enterprise - InternalOAuthError: Failed to obtain access token #57

Closed
besh opened this issue May 5, 2016 · 7 comments
Closed

Comments

@besh
Copy link

besh commented May 5, 2016

This might be an enterprise specific issue perhaps?

Here is my code

passport.js

passport.use(new GitHubStrategy({
    clientID: config.github.id,
    clientSecret: config.github.secret,
    callbackURL: 'http://127.0.0.1:3001/auth/github/callback',
    authorizationURL: 'https://github.our_domain.com/login/oauth/authorize'
  },
  function(accessToken, refreshToken, profile, cb) {
    console.log("accessToken==" + accessToken)
    User.findOrCreate({ githubId: profile.id }, function (err, user) {
      return cb(err, user);
    });
  }
));

server.js

app.get('/login/github',
  passport.authenticate('github', {session: false })
);

app.get('/auth/github/callback',
  passport.authenticate('github', { failureRedirect: '/login' }),
  (req, res) => {
    res.redirect('/');
  }
);

When I hit /login/github it bounces out to Github Enterprise, I give the app permissions, it then hits the callback and lands on http://127.0.0.1:3001/auth/github/callback?code=random_code with the above error.

Am I missing anything else? From what I understand (and I understand very little) it should obtain the token and I should be good to start hitting the GHE API.

Thanks!

@besh
Copy link
Author

besh commented May 6, 2016

Realized I needed to pass in two more options. userProfileURL and tokenURL

Now receiving this error:
Missing where attribute in the options parameter passed to findOrCreate. Please note that the API has changed, and is now options only

@besh
Copy link
Author

besh commented May 19, 2016

@jaredhanson Should I assume that this repo is no longer maintained and fork our own version?

@jaredhanson
Copy link
Owner

Why would you assume that?

Missing where attribute in the options parameter passed to findOrCreate. Please note that the API has changed, and is now options only

That error has nothing to do with this module, so forking won't help. It is in your application code.

@besh
Copy link
Author

besh commented May 19, 2016

@jaredhanson
My apologies. I only assumed because I opened a few weeks ago and noticed that #45 was from last year with no response.

passport-github was part of the error trace @ https://github.com/jaredhanson/passport-github/blob/master/lib/strategy.js#L174

@binario200
Copy link

binario200 commented Jun 7, 2016

I having same issue, could be because my machine is behid a corporate firewall?

Connect 500 InternalOAuthError: Failed to obtain access token at Strategy.OAuth2Strategy._createOAuthError (/usr/src/app/node_modules/passport-oauth2/lib/strategy.js:370:17) at /usr/src/app/node_modules/passport-oauth2/lib/strategy.js:166:45 at /usr/src/app/node_modules/oauth/lib/oauth2.js:177:18 at ClientRequest.<anonymous> (/usr/src/app/node_modules/oauth/lib/oauth2.js:148:5) at emitOne (events.js:96:13) at ClientRequest.emit (events.js:188:7) at TLSSocket.socketOnEnd (_http_client.js:342:9) at emitNone (events.js:91:20) at TLSSocket.emit (events.js:185:7) at endReadableNT (_stream_readable.js:926:12) at _combinedTickCallback (internal/process/next_tick.js:74:11) at process._tickCallback (internal/process/next_tick.js:98:9)

@rakesh113
Copy link

binario200 so how did u resolve it?

@binario200
Copy link

binario200 commented Nov 23, 2016

@rakesh113 At the begin I tried some workarrounds like setting proxy settings to the oauth request like as I documented here

Then I realize that passport-github works very well but with the "public" Github (maybe some hardcode github.com urls).

I was using Github Enterprise at my job so I finally decide to use simple-oauth2 to get authenticated by github enterprise and I finished with a solution like this

# using node + express: defining the routes. 
router.get('/auth/github', authController.getAuthentication);
router.get('/auth/github/callback', GHEAuthenticator.catch_callback, userController.createProfile);
# the controller 
exports.getAuthentication = function(req, res) {
 GHEAuthenticator.authenticate(req, res);
};
var dotenv = require('dotenv');
 dotenv.load({ path: '.env' });

 var oauth2 = require('simple-oauth2')({
     clientID: process.env.GITHUB_ID,
     clientSecret: process.env.GITHUB_SECRET,
     site: process.env.BASE_SITE,
     tokenPath: process.env.TOKEN_PATH,
     authorizationPath: process.env.AUTHORIZATION_PATH
 });

 var authorizeConfig = {
     redirect_uri: process.env.CALLBACKURL,
     scope: process.env.GITHUB_SCOPE,
     state: ''
 };

 catch_callback: function catch_callback(req, res, next) {

    var tokenConfig = {
      code: req.query.code,
      redirect_uri: process.env.CALLBACKURL
      //,expires_in: '7200'
    };

    oauth2.authCode.getToken(tokenConfig, saveToken);

    function saveToken(error, result) {
      if (error) {
        console.log('Error Saving Access Token ', error.message);
        return next(error);
      }

      //var token = oauth2.accessToken.create(result);
      var parsedAccessToken = oauthResultParser(result);
      req.session.AccessToken = parsedAccessToken;

      return next();
    }

  }

You can see the whole solution here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants