Last active
December 15, 2015 22:09
-
-
Save lilmuckers/5331033 to your computer and use it in GitHub Desktop.
GitHub authorisations API script for Flatiron.js, using Githubber library, and uses a configured client secret and client token.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var GitHub = require('githubber'); | |
//run the function | |
var github = module.exports = function github (cmd, cb) { | |
//setup the user input schema | |
var schema = { | |
properties: { | |
username: { | |
pattern: /^[a-zA-Z\s\-]+$/, | |
message: 'Username must be only letters, spaces, or dashes', | |
required: true | |
}, | |
password: { | |
hidden: true, | |
required: true | |
}, | |
note: { | |
message: 'Note to label this with on your GitHub control panel', | |
required: true | |
} | |
} | |
}; | |
//get the user data | |
this.prompt.get(schema, function (err, result) { | |
//set up the github api object | |
var ghObj = new GitHub.GitHub(); | |
var ghApi = new GitHub.GitHubAPI(ghObj, {username:result.username, password:result.password}); | |
//set up the oauth token | |
var data = { | |
scopes: ['repo'], | |
note: result.note | |
} | |
//create the oauth token and tell the user what to do with it | |
ghApi.oauth.create(data, function(err, oauth){ | |
console.log("Update your config file with this oauth token: "+oauth.token); | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment