Results 1 to 6 of 6
  1. #1
    Can I have your Tots Hydroxsis's Avatar
    Rank
    Forum Member
    Division
    None
    Status
    Active
    Join Date
    Mar 2015
    Age
    29
    Posts
    13

    Default Hey yall! was wondering if we have any API programmers

    I need some help with some homework and I've been struggling getting basic auth and Oauth working on a node.js api if anyone out there can offer a helping hand I'd be more than gracious!

  2. #2
    A Mighty Pirate!

    AOD_Guybrush's Avatar
    Rank
    Master Sergeant
    Division
    Destiny 2
    Status
    Active
    Join Date
    Sep 2014
    Location
    Raleigh, NC
    Age
    29
    Posts
    3,203

    Default

    Unfortunately not in nodeJS :(



  3. #3
    Can I have your Tots Hydroxsis's Avatar
    Rank
    Forum Member
    Division
    None
    Status
    Active
    Join Date
    Mar 2015
    Age
    29
    Posts
    13

    Default

    Dang :( thank you for replying at least! :D

  4. #4
    Looks like I picked the wrong week to quit sniffing glue Vonarus's Avatar
    Rank
    Forum Member
    Division
    None
    Status
    Active
    Join Date
    Mar 2015
    Posts
    34

    Default

    What are you trying to do specifically?

  5. #5
    Can I have your Tots Hydroxsis's Avatar
    Rank
    Forum Member
    Division
    None
    Status
    Active
    Join Date
    Mar 2015
    Age
    29
    Posts
    13

    Default

    I'm creating a nodeJS proxy that has two paths oauth and basic auth to communicate with github and get some simple information back (mainly just a successful request). I've gotten a token and everything is dandy there now but I'm working on a basic auth now and I'm a bit lost

    Heres a pop of the code to see so far if it helps

    Code:
    var express = require('express');
    var app = express();
    //Server-api config
    var port = process.env.PORT || 8080;
    var router = express.Router();
    //standard log all methods
    var http = require('http'),
        https = require ('https');
    
    var auth = express.basicAuth('Maxoriley618', 'Gunner131');
    
    router.use(function(req,res,next){
        console.log(req.method  + ' ' + req.url);
        next();
    });
    
    function testGitHub(userVar) {
        var GitHubApi = require("github");
        var github = new GitHubApi({
            // required
            version: "3.0.0"
        });
    
        github.authenticate({
            type: "basic",
            username: "Maxoriley618",
            password: "Gunner131"
        });
    
        var token = "db1e8c41ac1214f813ac00d02c3ca28e49b9a2f8";
    
        github.authenticate({
            type: "oauth",
            token: token
        });
       github.user({ user: userVar} , function(err, res) {
            console.log("GOT ERR?", err);
            console.log("GOT RES?", res);
            github.repos.getAll({}, function(err, res) {
                console.log("GOT ERR?", err);
                console.log("GOT RES?", res);
            });
        });
    }
    //ROUTES
    //BASIC rout for basic auth
    router.route('/basic')
       .get(function(req,res) {
            if(req.headers['user'] == null)
            {
                res.status(405).json({message: 'a user is required!'});
            }
            else res.json({message: 'Github users login: ' + JSON.stringify(req.headers['user'])});
        })
        //reject unsupported HTTP methods
        .all(function(req, res) {
            res.status(405).json({message: 'Does not support this HTTP method'});
        });
    router.route('/oauth')
        .get(
        function(req,res) {
            if(req.headers['user'] == null)
            {
                res.status(405).json({message: 'a user is required!'});
            }
            else  res.json({message: 'Github users login: ' + JSON.stringify(req.headers['user'])});
        })
        //reject unsupported HTTP methods
        .all(function(req, res) {
            res.status(405).json({message: 'Does not support this HTTP method'});
        });
    
    app.use('/api', router);
    
    //BLOCK ANY OTHER REQUESTS
    //==================================================================================================================
    //catch all other requests and reject
    app.all('*', function(req, res) {
        res.status(404).send('Invalid/Rejected URN', req.query);
    });
    
    //START THE SERVER
    //==================================================================================================================
    app.listen(port);
    console.log('Started. Listening on port:' + port);

  6. #6
    Can I have your Tots Hydroxsis's Avatar
    Rank
    Forum Member
    Division
    None
    Status
    Active
    Join Date
    Mar 2015
    Age
    29
    Posts
    13

    Default

    Oh it also has to be done on apigee


 

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
vBulletin Skin By: ForumThemes.com
Top