v1.2.5: allow some storage configuration for node
This commit is contained in:
parent
df6b77daf5
commit
667fbbab3a
|
@ -38,7 +38,6 @@ OAUTH3._base64.atob = function (base64) {
|
|||
OAUTH3._base64.btoa = function (text) {
|
||||
return new Buffer(text, 'utf8').toString('base64');
|
||||
};
|
||||
OAUTH3._defaultStorage = require('./oauth3.node.storage');
|
||||
|
||||
OAUTH3._node = {};
|
||||
OAUTH3._node.discover = function(providerUri/*, opts*/) {
|
||||
|
@ -107,5 +106,13 @@ OAUTH3._node.randomState = function () {
|
|||
return crypto.randomBytes(16).toString('hex');
|
||||
};
|
||||
OAUTH3.randomState = OAUTH3._node.randomState;
|
||||
OAUTH3._nodeCreate = OAUTH3.create;
|
||||
OAUTH3.create = function (loc, opts) {
|
||||
if (!loc) {
|
||||
loc = {};
|
||||
}
|
||||
OAUTH3._defaultStorage = require('./oauth3.node.storage').create(loc, opts);
|
||||
return OAUTH3._nodeCreate.apply(OAUTH3, arguments);
|
||||
};
|
||||
|
||||
module.exports = OAUTH3;
|
||||
|
|
|
@ -1,34 +1,54 @@
|
|||
'use strict';
|
||||
|
||||
var PromiseA = require('bluebird');
|
||||
var fs = PromiseA.promisifyAll(require('fs'));
|
||||
var PromiseA;
|
||||
try {
|
||||
PromiseA = require('bluebird');
|
||||
} catch(e) {
|
||||
PromiseA = global.Promise;
|
||||
}
|
||||
var promisify = PromiseA.promisify || require('util').promisify;
|
||||
var fs = {
|
||||
existsSync: require('fs').existsSync
|
||||
, mkdirSync: require('fs').mkdirSync
|
||||
, readdirAsync: promisify(require('fs').readdir)
|
||||
, writeFileAsync: promisify(require('fs').writeFile)
|
||||
, unlinkAsync: promisify(require('fs').unlink)
|
||||
};
|
||||
var path = require('path');
|
||||
//var oauth3dir = process.cwd();
|
||||
var oauth3dir = path.join(require('os').homedir(), '.oauth3', 'v1');
|
||||
var sessionsdir = path.join(oauth3dir, 'sessions');
|
||||
var directivesdir = path.join(oauth3dir, 'directives');
|
||||
var metadir = path.join(oauth3dir, 'meta');
|
||||
|
||||
// We can reasonably assume the existence of the home directory, but we can't assume
|
||||
// that there will already be a `.oauth3` directory or anything inside of it.
|
||||
if (!fs.existsSync(path.join(oauth3dir, '..'))) {
|
||||
fs.mkdirSync(path.join(oauth3dir, '..'));
|
||||
}
|
||||
if (!fs.existsSync(oauth3dir)) {
|
||||
fs.mkdirSync(oauth3dir);
|
||||
}
|
||||
if (!fs.existsSync(directivesdir)) {
|
||||
fs.mkdirSync(directivesdir);
|
||||
}
|
||||
if (!fs.existsSync(sessionsdir)) {
|
||||
fs.mkdirSync(sessionsdir);
|
||||
}
|
||||
if (!fs.existsSync(metadir)) {
|
||||
fs.mkdirSync(metadir);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
directives: {
|
||||
create: function (loc/*, opts*/) {
|
||||
var oauth3dir;
|
||||
if (!loc.pathname) {
|
||||
loc.pathname = require('os').hostname();
|
||||
oauth3dir = path.join(loc.pathname, '.config/oauth3.org');
|
||||
} else {
|
||||
oauth3dir = path.join(loc.pathname, 'oauth3.org', 'v1');
|
||||
}
|
||||
var sessionsdir = path.join(oauth3dir, 'sessions');
|
||||
var directivesdir = path.join(oauth3dir, 'directives');
|
||||
var metadir = path.join(oauth3dir, 'meta');
|
||||
|
||||
// We can reasonably assume the existence of the home directory, but we can't assume
|
||||
// that there will already be a `.oauth3` directory or anything inside of it.
|
||||
if (!fs.existsSync(path.join(oauth3dir, '..'))) {
|
||||
fs.mkdirSync(path.join(oauth3dir, '..'));
|
||||
}
|
||||
if (!fs.existsSync(oauth3dir)) {
|
||||
fs.mkdirSync(oauth3dir);
|
||||
}
|
||||
if (!fs.existsSync(directivesdir)) {
|
||||
fs.mkdirSync(directivesdir);
|
||||
}
|
||||
if (!fs.existsSync(sessionsdir)) {
|
||||
fs.mkdirSync(sessionsdir);
|
||||
}
|
||||
if (!fs.existsSync(metadir)) {
|
||||
fs.mkdirSync(metadir);
|
||||
}
|
||||
|
||||
var OAUTH3 = {};
|
||||
OAUTH3.directives = {
|
||||
all: function () {
|
||||
return fs.readdirAsync(directivesdir).then(function (nodes) {
|
||||
return nodes.map(function (node) {
|
||||
|
@ -63,9 +83,8 @@ module.exports = {
|
|||
}));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
, sessions: {
|
||||
};
|
||||
OAUTH3.sessions = {
|
||||
all: function (providerUri) {
|
||||
return fs.readdirAsync(sessionsdir).then(function (nodes) {
|
||||
return nodes.map(function (node) {
|
||||
|
@ -118,8 +137,8 @@ module.exports = {
|
|||
}));
|
||||
});
|
||||
}
|
||||
}
|
||||
, meta: {
|
||||
};
|
||||
OAUTH3.meta = {
|
||||
get: function (key) {
|
||||
// TODO make safe
|
||||
try {
|
||||
|
@ -133,5 +152,8 @@ module.exports = {
|
|||
return value;
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
return OAUTH3;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "oauth3.js",
|
||||
"version": "1.2.4",
|
||||
"version": "1.2.5",
|
||||
"description": "The world's smallest, fastest, and most secure OAuth3 (and OAuth2) JavaScript implementation.",
|
||||
"main": "oauth3.node.js",
|
||||
"scripts": {
|
||||
|
|
Loading…
Reference in New Issue