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

Require functionality for webapp flow integrations #512

Closed
deveshks opened this issue Feb 26, 2017 · 6 comments
Closed

Require functionality for webapp flow integrations #512

deveshks opened this issue Feb 26, 2017 · 6 comments

Comments

@deveshks
Copy link

Hi,

Currently there is no support for the web-application flow of github developer's api, as detailed here.
https://gist.github.com/technoweenie/419219

I am able to follow a manual implementation of the same, taking the inspiration from here. https://github.com/criso/fbgraph#rockin-it-on-an-express-app

It would be great if a support can be provided to make this easier.

qs = require('qs')
var Client = require('node-rest-client').Client;
var client = new Client();

///This piece of code can go inside a function which can be called by a url, e.g. by a expressjs router

    //We don't have the code, calling the oauth2 dialog
     if (!req.query.code) {

          params = {
            "client_id":conf.client_id,
            "redirect_uri":conf.redirect_uri
          }
          var getCodeUrl = "https://github.com/login/oauth/authorize?"+qs.stringify(params)
          if (!req.query.error) { 
     //hit the oauth2 dialog
      res.redirect(getCodeUrl);
    } else { 
      res.send('access denied');
    }
  }
 //We got the code after accepting oauth dialog
  else {
      params = {
            "client_id":conf.client_id,
            "redirect_uri":conf.redirect_uri,
            "client_secret":conf.client_secret,
            "code":req.query.code
          }
      var args = {
    headers: { "Content-Type": "application/json","Accept": "application/json" }
};
   //use the code now to get access token
    var getTokenUrl = "https://github.com/login/oauth/access_token?"+qs.stringify(params)
    client.post(getTokenUrl, args, function (data, response) {
      acesstoken = data.access_token;
    //got access token, authenticate using it and start calling api's
        github.authenticate({
            type: "oauth",
            token: authtoken
        });
        github.repos.getAll({
    "affiliation": "owner,organization_member"
}, function(err, res) {
    console.log(err, res);
});
        
});

  }
@jeffwilcox
Copy link

Isn't this delegated to your authentication flow library of choice? For example, passport and passport-github, and then using the existing authenticate method on this library to use that value?

@kaizensoze
Copy link

Yeah I'd rather leave it up to the user than bake it into the library.

@deveshks
Copy link
Author

Yes, that is fair. But you can always bake it in the library, but not make it mandatory, leaving them to their choice of either using the in-house auth, or a 3rd party.

@kaizensoze
Copy link

Sure, but on the other hand I'd like to keep the library dependencies minimal. I'm not sure I want to include it in the library at the moment, even in the form of a pull request, but I'll think about it.

@deveshks
Copy link
Author

Sure, but the changes I proposed would not entail any dependency on external libraries, just a few added method and declarations to give a user an alternate of not going to a third party lib. Let me know if I can contribute in that endeavour

@kaizensoze
Copy link

Going to keep it simple and keep the web-application flow stuff separate.

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

3 participants