GitHub API oAuth For your command line helpers
Enter in your username, password, and the scopes you want the oAuth token to cover, along with a note so that you know what this oAuth is for, y'know, it's handy. I can assure that this code does not save the password anywhere and merely uses it to log into GitHub and set up a new authorisation token. If you want to check it out, the code for this is in the gist below (I'm using the gist as the hosting for the script too, just so you can be 100% sure there's no funny business). There is a bit of Google Analytics event tracking, purely for my own curiosity as to how much it is used, but it doesn't track anything except for the fact that it is being used, if it succeeds, or if it fails.
In recent months i've had many occasions where I've needed to use the GitHub API, for both personal projects and under the aegis of stuff i've done for work. The main obstical I've had is that if you're building a command line tool, as I usually do for these things, there isn't a nice way to get an oAuth token, like there is for a web app.
As I'm sure you're aware when you're using oAuth with a web app, you get forewarded to a nice GitHub login page where you accept/deny the request to allow the application access to your github account. This isn't really possible when what you're doing is a command line tool. Moreover when you're building a tool that is only going to be used by yourself, or by a small closed set of developers, you don't really need that added niceness layer, you just need the oAuth access token so you can get on with what you need to do.
Fortunately GitHub have an API method that is just the solution to this, it's the authorisations API, where you can pass a username and a password to get an oAuth token in return, handily meaning you don't have to store the users password in some plain text.
As you can see; it's a pretty simple script.
So. You know. There's that.
Related Posts They might not be good...
- Tech - 7 posts