update sessions api
This commit is contained in:
parent
cf6c1b9e5a
commit
5047fc1aff
|
@ -4,10 +4,17 @@
|
|||
var form = require('terminal-forms.js').create(process.stdin, process.stdout);
|
||||
var OAUTH3 = require('../oauth3.node.js');
|
||||
// TODO change to ._hooks
|
||||
OAUTH3.hooks.directives._get = require('../oauth3.node.storage.js').directives._get;
|
||||
OAUTH3._hooks = require('../oauth3.node.storage.js');
|
||||
// directives = { get, set }
|
||||
// sessions = { get, set }
|
||||
OAUTH3.hooks.directives._set = require('../oauth3.node.storage.js').directives._set;
|
||||
OAUTH3.hooks.session._get = require('../oauth3.node.storage.js').session._get;
|
||||
OAUTH3.hooks.session._set = require('../oauth3.node.storage.js').session._set;
|
||||
OAUTH3._hooks.directives.get = require('../oauth3.node.storage.js').directives._get;
|
||||
OAUTH3._hooks.directives.set = require('../oauth3.node.storage.js').directives._set;
|
||||
OAUTH3._hooks.session.get = require('../oauth3.node.storage.js').session._get;
|
||||
OAUTH3._hooks.session.set = require('../oauth3.node.storage.js').session._set;
|
||||
|
||||
var url = require('url');
|
||||
//console.log('stdin tty', process.stdin.isTTY);
|
||||
//console.log('stdout tty', process.stdout.isTTY);
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 66d46eab32d8014f43307f9fbe97027b8c913f7a
|
||||
Subproject commit 3f2e11a41d5dbf5903abbf457eba3b2f3ec6a1d8
|
|
@ -417,13 +417,19 @@
|
|||
return OAUTH3.PromiseA.resolve(OAUTH3.hooks.directives._set(providerUri, directives));
|
||||
}
|
||||
, _get: function (providerUri) {
|
||||
console.warn('[Warn] Please implement OAUTH3.hooks.directives._get = function (providerUri) { return PromiseA<directives>; }');
|
||||
return JSON.parse(window.localStorage.getItem('directives-' + providerUri) || '{}');
|
||||
if (!OAUTH3._hooks || !OAUTH3._hooks.directives || !OAUTH3._hooks.directives.get) {
|
||||
console.warn('[Warn] Please implement OAUTH3._hooks.directives.get = function (providerUri) { return PromiseA<directives>; }');
|
||||
return JSON.parse(window.localStorage.getItem('directives-' + providerUri) || '{}');
|
||||
}
|
||||
return OAUTH3._hooks.directives.get(providerUri);
|
||||
}
|
||||
, _set: function (providerUri, directives) {
|
||||
console.warn('[Warn] Please implement OAUTH3.hooks.directives._set = function (providerUri, directives) { return PromiseA<directives>; }');
|
||||
window.localStorage.setItem('directives-' + providerUri, JSON.stringify(directives));
|
||||
return directives;
|
||||
if (!OAUTH3._hooks || !OAUTH3._hooks.directives || !OAUTH3._hooks.directives.set) {
|
||||
console.warn('[Warn] Please implement OAUTH3._hooks.directives.set = function (providerUri, directives) { return PromiseA<directives>; }');
|
||||
window.localStorage.setItem('directives-' + providerUri, JSON.stringify(directives));
|
||||
return directives;
|
||||
}
|
||||
return OAUTH3._hooks.directives.set(providerUri, directives);
|
||||
}
|
||||
}
|
||||
, session: {
|
||||
|
@ -509,41 +515,61 @@
|
|||
return newSession; // oauth3.hooks.refreshSession(expiredSession, newSession);
|
||||
});
|
||||
}
|
||||
, _getCached: function (providerUri) {
|
||||
, _getCached: function (providerUri, id) {
|
||||
providerUri = OAUTH3.uri.normalize(providerUri);
|
||||
if (!OAUTH3.hooks.session._cache) { OAUTH3.hooks.session._cache = {}; }
|
||||
if (id) {
|
||||
return OAUTH3.hooks.session._cache[providerUri + id];
|
||||
}
|
||||
return OAUTH3.hooks.session._cache[providerUri];
|
||||
}
|
||||
, set: function (providerUri, newSession) {
|
||||
, set: function (providerUri, newSession, id) {
|
||||
if (!providerUri) {
|
||||
console.error(new Error('no providerUri').stack);
|
||||
throw new Error("providerUri is not set");
|
||||
}
|
||||
providerUri = OAUTH3.uri.normalize(providerUri);
|
||||
if (!OAUTH3.hooks.session._cache) { OAUTH3.hooks.session._cache = {}; }
|
||||
OAUTH3.hooks.session._cache[providerUri] = newSession;
|
||||
OAUTH3.hooks.session._cache[providerUri + (id || newSession.id || newSession.token.id || '')] = newSession;
|
||||
if (!id) {
|
||||
OAUTH3.hooks.session._cache[providerUri] = newSession;
|
||||
}
|
||||
return OAUTH3.PromiseA.resolve(OAUTH3.hooks.session._set(providerUri, newSession));
|
||||
}
|
||||
, get: function (providerUri) {
|
||||
, get: function (providerUri, id) {
|
||||
providerUri = OAUTH3.uri.normalize(providerUri);
|
||||
if (!providerUri) {
|
||||
throw new Error("providerUri is not set");
|
||||
}
|
||||
|
||||
return OAUTH3.PromiseA.resolve(OAUTH3.hooks.session._getCached(providerUri)
|
||||
|| OAUTH3.hooks.session._get(providerUri)).then(function (session) {
|
||||
OAUTH3.hooks.session._cache[providerUri] = session;
|
||||
return OAUTH3.PromiseA.resolve(
|
||||
OAUTH3.hooks.session._getCached(providerUri, id) || OAUTH3.hooks.session._get(providerUri, id)
|
||||
).then(function (session) {
|
||||
OAUTH3.hooks.session._cache[providerUri + (id || session.id || session.token.id || '')] = session;
|
||||
if (!id) {
|
||||
OAUTH3.hooks.session._cache[providerUri] = session;
|
||||
}
|
||||
return session;
|
||||
});
|
||||
}
|
||||
, _get: function (providerUri) {
|
||||
console.warn('[Warn] Please implement OAUTH3.hooks.session._get = function (providerUri) { return PromiseA<savedSession>; }');
|
||||
return JSON.parse(window.localStorage.getItem('session-' + providerUri) || 'null');
|
||||
, _get: function (providerUri, id) {
|
||||
if (!OAUTH3._hooks || !OAUTH3._hooks.sessions || !OAUTH3._hooks.sessions.all) {
|
||||
console.warn('[Warn] Please implement OAUTH3._hooks.sessions.all = function ([providerUri]) { return PromiseA<sessions>; }');
|
||||
}
|
||||
if (!OAUTH3._hooks || !OAUTH3._hooks.sessions || !OAUTH3._hooks.sessions.get) {
|
||||
console.warn('[Warn] Please implement OAUTH3._hooks.sessions.get = function (providerUri[, id]) { return PromiseA<session>; }');
|
||||
return JSON.parse(window.sessionStorage.getItem('session-' + providerUri + (id || '')) || 'null');
|
||||
}
|
||||
return OAUTH3._hooks.directives.get(providerUri, id);
|
||||
}
|
||||
, _set: function (providerUri, newSession) {
|
||||
console.warn('[Warn] Please implement OAUTH3.hooks.session._set = function (providerUri, newSession) { return PromiseA<newSession>; }');
|
||||
window.localStorage.setItem('session-' + providerUri, JSON.stringify(newSession));
|
||||
return newSession;
|
||||
, _set: function (providerUri, newSession, id) {
|
||||
if (!OAUTH3._hooks || !OAUTH3._hooks.sessions || !OAUTH3._hooks.sessions.set) {
|
||||
console.warn('[Warn] Please implement OAUTH3._hooks.sessions.set = function (providerUri, newSession[, id]) { return PromiseA<newSession>; }');
|
||||
window.sessionStorage.setItem('session-' + providerUri, JSON.stringify(newSession));
|
||||
window.sessionStorage.setItem('session-' + providerUri + (id || newSession.id || newSession.token.id || ''), JSON.stringify(newSession));
|
||||
return newSession;
|
||||
}
|
||||
return OAUTH3._hooks.directives.set(providerUri, newSession, id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue