oauth3.js/oauth3.node.storage.js

47 lines
1.2 KiB
JavaScript
Raw Normal View History

2017-03-21 05:29:03 +00:00
'use strict';
var fs = require('fs');
var path = require('path');
module.exports = {
directives: {
get: function (providerUri) {
2017-03-21 05:29:03 +00:00
// TODO make safe
try {
return require(path.join(process.cwd(), providerUri + '.directives.json'));
} catch(e) {
return null;
}
}
, set: function (providerUri, directives) {
2017-03-21 05:29:03 +00:00
fs.writeFileSync(path.join(process.cwd(), providerUri + '.directives.json'), JSON.stringify(directives, null, 2));
return directives;
}
}
2017-03-21 07:02:41 +00:00
, sessions: {
get: function (providerUri, id) {
2017-03-21 07:02:41 +00:00
// TODO make safe
try {
if (id) {
return require(path.join(process.cwd(), providerUri + '.' + id + '.session.json'));
}
else {
return require(path.join(process.cwd(), providerUri + '.session.json'));
}
2017-03-21 07:02:41 +00:00
} catch(e) {
return null;
}
}
, set: function (providerUri, session, id) {
if (id) {
fs.writeFileSync(path.join(process.cwd(), providerUri + '.' + id + '.session.json'), JSON.stringify(session, null, 2));
}
else {
fs.writeFileSync(path.join(process.cwd(), providerUri + '.session.json'), JSON.stringify(session, null, 2));
}
2017-03-21 07:02:41 +00:00
return session;
}
}
2017-03-21 05:29:03 +00:00
};