Created
December 6, 2015 09:38
-
-
Save simov/d91a0c92dffe4a704fe7 to your computer and use it in GitHub Desktop.
Server Side Explicit OAuth Flow automation with NodeJS, NWjs and Grant
This file contains 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": "server-side-explicit-oauth-flow", | |
"main": "authorize.html", | |
"window": { | |
"show": false, | |
"show_in_taskbar": false | |
} | |
} |
This file contains 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 path = require('path') | |
var child = require('child_process') | |
var express = require('express') | |
var session = require('express-session') | |
var Grant = require('grant-express') | |
var config = { | |
server: { | |
protocol: 'http', | |
host: 'localhost:3000' | |
}, | |
instagram: { | |
key: '[CLIENT_ID]', | |
secret: '[CLIENT_SECRET]', | |
callback: '/callback' | |
} | |
} | |
var nw = null | |
var app = express() | |
app.use(session({secret: 'very secret'})) | |
app.use(new Grant(config)) | |
app.get('/connect', function (req, res) { | |
var dpath = path.resolve(__dirname) | |
nw = child.spawn('nw', [dpath]) | |
res.end() | |
}) | |
app.get('/callback', function (req, res) { | |
console.log(req.query) | |
nw.on('close', function (code, signal) { | |
console.log('NW closed') | |
}) | |
nw.kill('SIGHUP') | |
res.end() | |
}) | |
app.listen(3000, function () { | |
console.log('Express server listening on port ' + 3000) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment