Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('can create a new token', function (done) {
// Mock the api responses
var creds = {
username: 'fakeuser',
password: 'fakepass'
},
configSpy = sandbox.spy(octonode.auth, 'config'),
loginStub = sandbox.stub(octonode.auth, 'login', function (scopes, cb) {
cb(null, 1, 'Created Token');
});
auth.askForGithubCredentials = sandbox.stub().returns(Promise.resolve(creds));
auth.saveToken = sandbox.stub().returns(Promise.resolve({
saveto: 'fakepath',
tokenId: 1,
token: 'Created Token'
}));
auth.token().then(function (token) {
configSpy.calledWithExactly(creds).should.equal(true);
token.should.equal('Created Token');
done();
oauth.login = function(req, res) {
var gotoNextStep = !!req.query.next_step;
if (req.session.loginName) {
// if has session.loginName, logined
res.redirect(302, '/' + (gotoNextStep ? '#step-2' : ''));
return;
}
// oauth login url
var authUrl = github.auth.login(['read:org']);
// Store info to verify against CSRF
req.session.authState = authUrl.match(/&state=([0-9a-z]{32})/i)[1];
if (gotoNextStep) {
req.session.gotoNextStep = true;
}
res.redirect(302, authUrl);
};
exports.auth = function(req, res) {
res.contentType('application/json');
// authenticate
github.auth.config({
username: req.params.user,
password: req.params.pass
}).login(['user', 'repo', 'gist'], function(err, id, token) {
settings.token = token; // save the client token
settings.client = github.client(settings.token); // create a client object
settings.client.get('/user', function(err, status, body) { // get user details
settings.info = body;
});
ghgist = settings.client.gist(); // create a reference to gist api
res.send({
id: id,
token: token,
err: err
});
});
getGithubToken = function (credentials) {
octonode.auth.config(credentials);
var authRequestData = {
scopes: ['gist', 'repo'],
// TODO: Include current working directory name or something instead of date?
note: 'git-at-me created on ' + (new Date().toDateString())
},
getAuthToken = Promise.promisify(octonode.auth.login, octonode.auth);
return getAuthToken(authRequestData);
};
/*jshint laxbreak:true */
/*
* GET login / auth page.
*/
var Q = require('q');
var nconf = require('nconf');
var github = require('octonode');
var User = require('../models/User');
var winston = require('winston');
var oauth = {};
github.auth.config({
id: nconf.get('github:clientId'),
secret: nconf.get('github:clientSecret')
});
oauth.login = function(req, res) {
var gotoNextStep = !!req.query.next_step;
if (req.session.loginName) {
// if has session.loginName, logined
res.redirect(302, '/' + (gotoNextStep ? '#step-2' : ''));
return;
}
// oauth login url
var authUrl = github.auth.login(['read:org']);
// Store info to verify against CSRF
req.session.authState = authUrl.match(/&state=([0-9a-z]{32})/i)[1];
if (gotoNextStep) {
var authCallback = function(req, res, next) {
var cookies = new Cookies(req, res);
github.auth.login(req.query.code, function(err, token) {
// If we got a token, save it to a cookie
if (token) {
tokenHelpers.setToken(cookies, token);
}
// Then redirect the user
res.writeHead(301, {'Content-Type': 'text/plain', 'Location': '/'});
res.end();
});
};
exports.auth = function(req, res) {
res.contentType('application/json');
// authenticate
github.auth.config({
username: req.params.user,
password: req.params.pass
}).login(['user', 'repo', 'gist'], function(err, id, token) {
settings.token = token; // save the client token
settings.client = github.client(settings.token); // create a client object
settings.client.get('/user', function(err, status, body) { // get user details
settings.info = body;
});
ghgist = settings.client.gist(); // create a reference to gist api
res.send({
id: id,
token: token,
err: err
});
});
url: function() {
var clientInfo = require('../../config/client-info.json')[ENV];
return github.auth.config({
id: clientInfo.clientId,
secret: clientInfo.clientSecret
}).login(['gist']);
}
};
'use strict';
const config = require('config');
const github = require('octonode');
const {stringify} = require('querystring');
const {wrap} = require('co');
const rp = require('request-promise');
const {promisifyAll} = require('bluebird');
const CLIENT_ID = config.get('github.clientID');
const CLIENT_SECRET = config.get('github.clientSecret');
const CALLBACK_URL = config.get('github.callbackURL');
promisifyAll(Object.getPrototypeOf(github.client()), {multiArgs: true});
github.auth.config({
id: CLIENT_ID,
secret: CLIENT_SECRET,
});
function createLoginUrl() {
const queryStr = stringify({
client_id: CLIENT_ID,
redirect_uri: CALLBACK_URL,
state: Date.now(),
});
return `https://github.com/login/oauth/authorize?${queryStr}`;
}
const handleLoginCallback = wrap(function *({code, state}) {
const {access_token} = yield rp({
method: 'POST',
var app = module.exports = require('express')();
var config = require('config');
var github = require('octonode');
var authURL = github.auth.config({
id: config.github.id,
secret: config.github.secret
}).login([]);
app.get('/github', function(req, res) {
res.redirect(authURL);
});
app.get('/github/callback', function(req, res) {
github.auth.login(req.query.code, function(err, token) {
var client = github.client(token);
client.me().info(function(err, info) {
if (err || !info) {
return res.end(err.message);
}
User.findOrCreate({