Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
eb6881a350 | |||
1ec659f8c7 | |||
4d27e4579d | |||
c384efeb71 |
16
indieauth.js
16
indieauth.js
|
@ -1,4 +1,5 @@
|
|||
var Micropub = require('micropub-helper');
|
||||
var crypto = require('crypto');
|
||||
|
||||
module.exports = function (RED) {
|
||||
function IndieauthNode(n) {
|
||||
|
@ -15,12 +16,16 @@ module.exports = function (RED) {
|
|||
|
||||
RED.httpAdmin.get('/indieauth/auth', function (req, res) {
|
||||
var node_id = req.query.id;
|
||||
var redirect_uri = req.query.callback;
|
||||
|
||||
var random_part = crypto.randomBytes(20).toString('hex');
|
||||
var state = node_id + ':' + random_part;
|
||||
|
||||
const micropub = new Micropub({
|
||||
clientId: req.query.client_id,
|
||||
redirectUri: 'http://localhost:1881/indieauth/auth/callback',
|
||||
redirectUri: redirect_uri,
|
||||
me: req.query.me,
|
||||
state: node_id + ':1234'
|
||||
state: state
|
||||
});
|
||||
|
||||
var credentials = {
|
||||
|
@ -31,6 +36,8 @@ module.exports = function (RED) {
|
|||
micropub.getAuthUrl(req.query.me).then(url => {
|
||||
credentials.micropub_endpoint = micropub.options.micropubEndpoint;
|
||||
credentials.token_endpoint = micropub.options.tokenEndpoint;
|
||||
credentials.redirect_uri = redirect_uri;
|
||||
credentials.state = state;
|
||||
res.redirect(url);
|
||||
RED.nodes.addCredentials(node_id, credentials);
|
||||
}).catch(err => {
|
||||
|
@ -40,9 +47,6 @@ module.exports = function (RED) {
|
|||
});
|
||||
|
||||
RED.httpAdmin.get('/indieauth/auth/callback', function (req, res) {
|
||||
RED.log.info(req.query.state);
|
||||
RED.log.info(req.query.code);
|
||||
|
||||
var code = req.query.code;
|
||||
var state = req.query.state.split(':');
|
||||
|
||||
|
@ -59,7 +63,7 @@ module.exports = function (RED) {
|
|||
|
||||
const micropub = new Micropub({
|
||||
clientId: credentials.client_id,
|
||||
redirectUri: 'http://localhost:1881/indieauth/auth/callback',
|
||||
redirectUri: credentials.redirect_uri,
|
||||
tokenEndpoint: credentials.token_endpoint,
|
||||
state: req.query.state,
|
||||
me: credentials.me,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name" : "node-red-contrib-micropub",
|
||||
"version": "0.3.0",
|
||||
"version": "0.4.0",
|
||||
"description": "Node that publishes to micropub endpoints",
|
||||
"dependencies": {
|
||||
"micropub-helper": "1.5.3"
|
||||
|
@ -11,5 +11,10 @@
|
|||
"indieauth": "indieauth.js",
|
||||
"micropub-create": "micropub-create.js"
|
||||
}
|
||||
},
|
||||
"repository": "github:pstuifzand/node-red-contrib-micropub",
|
||||
"bugs": {
|
||||
"url" : "https://github.com/pstuifzand/node-red-contrib-micropub/issues",
|
||||
"email" : "node-red@p83.nl"
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user