Last active
October 9, 2022 09:59
-
-
Save cowboy/491b17ffb99d6838bdd2 to your computer and use it in GitHub Desktop.
node.js: in-browser github oauth from cli
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 githubOAuth = require('github-oauth')({ | |
githubClient: process.env['GITHUB_CLIENT'], | |
githubSecret: process.env['GITHUB_SECRET'], | |
baseURL: 'http://localhost:9001', | |
loginURI: '/login', | |
callbackURI: '/callback', | |
scope: 'user', | |
}); | |
require('http').createServer(function(req, res) { | |
if (req.url.match(/login/)) return githubOAuth.login(req, res); | |
if (req.url.match(/callback/)) { | |
githubOAuth.callback(req, res); | |
res.end('You may close this window now.'); | |
} | |
}).listen(9001); | |
githubOAuth.on('error', function(err) { | |
console.error('there was a login error', err); | |
process.exit(); | |
}); | |
githubOAuth.on('token', function(token, serverResponse) { | |
console.log('<TOKEN=%s>', token.access_token); | |
// do next steps instead of quitting | |
process.exit(); | |
}); | |
require('openurl').open('http://localhost:9001/login'); |
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
{ | |
"name": "node-github-oauth-wtf", | |
"version": "1.0.0", | |
"description": "such a thing is possible :p", | |
"main": "index.js", | |
"scripts": { | |
"install": "node ." | |
}, | |
"dependencies": { | |
"github-oauth": "^0.2.1", | |
"openurl": "^1.1.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://localhost:9001
http://localhost:9001/callback