bugfix base64 replacement, session retrieval

This commit is contained in:
AJ ONeal 2017-03-02 00:37:45 -07:00
parent eff1fd1127
commit 96a105c5f2
2 changed files with 20 additions and 9 deletions

View File

@ -38,9 +38,10 @@
, encodeUrlSafe: function (b64) {
// for directive passing in .well-known/oauth3
// Base64 to URL-safe Base64
b64 = OAUTH3._base64.btoa(b64);
b64 = b64.replace(/\+/g, '-').replace(/\//g, '_');
b64 = b64.replace(/=+/g, '');
return OAUTH3._base64.btoa(b64);
return b64;
}
}
, uri: {
@ -510,7 +511,7 @@
}
, _getCached: function (providerUri) {
providerUri = OAUTH3.uri.normalize(providerUri);
return OAUTH3.hooks.session._sessions[providerUri];
return OAUTH3.hooks.session._cache[providerUri];
}
, set: function (providerUri, newSession) {
if (!providerUri) {
@ -518,8 +519,8 @@
throw new Error("providerUri is not set");
}
providerUri = OAUTH3.uri.normalize(providerUri);
if (!OAUTH3.hooks.session._sessions) { OAUTH3.hooks.session._sessions = {}; }
OAUTH3.hooks.session._sessions[providerUri] = newSession;
if (!OAUTH3.hooks.session._cache) { OAUTH3.hooks.session._cache = {}; }
OAUTH3.hooks.session._cache[providerUri] = newSession;
return OAUTH3.PromiseA.resolve(OAUTH3.hooks.session._set(providerUri, newSession));
}
, get: function (providerUri) {
@ -527,10 +528,13 @@
if (!providerUri) {
throw new Error("providerUri is not set");
}
if (!OAUTH3.hooks.session._sessions) { OAUTH3.hooks.session._sessions = {}; }
if (!OAUTH3.hooks.session._cache) { OAUTH3.hooks.session._cache = {}; }
return OAUTH3.PromiseA.resolve(OAUTH3.hooks.session._sessions[providerUri]
|| OAUTH3.hooks.session._get(providerUri) || null);
return OAUTH3.PromiseA.resolve(OAUTH3.hooks.session._cache[providerUri]
|| OAUTH3.hooks.session._get(providerUri)).then(function (session) {
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>; }');
@ -1036,8 +1040,16 @@
});
});
}
, checkSession: function () {
return OAUTH3.hooks.session.get(this._providerUri);
}
, login: function (opts) {
var me = this;
if (me.session()) {
me._session = true;
return OAUTH3.PromiseA.resolve(me.session());
}
opts = opts || {};
opts.client_uri = me._clientUri;
@ -1047,7 +1059,7 @@
});
}
, session: function () {
return JSON.parse(JSON.stringify(OAUTH3.hooks.session._getCached(this._providerUri)));
return JSON.parse(JSON.stringify(OAUTH3.hooks.session._getCached(this._providerUri) || {}));
}
, request: function (preq, opts) {
opts = opts || {};

View File

@ -1 +0,0 @@
oauth3.core.js