cleaned up all uses of `_getCached` on hooks

the _getCached function disappeared when the hooks were re-written, but some
of the places that still relied on the old way of things still survived
This commit is contained in:
tigerbot 2017-11-08 19:03:28 -07:00
parent 69d5cb382a
commit 4d4d1af45d
1 changed files with 51 additions and 35 deletions

View File

@ -717,7 +717,9 @@
}
else {
// Discovery must take place before calling implicitGrant
promise = OAUTH3._implicitGrant(OAUTH3.hooks.directives._getCached(providerUri), opts);
promise = OAUTH3.hooks.directives.get(providerUri).then(function (directives) {
return OAUTH3._implicitGrant(directives, opts);
});
}
return promise.then(function (tokens) {
@ -815,9 +817,11 @@
});
}
, logout: function(providerUri, opts) {
return OAUTH3._logoutHelper(OAUTH3.hooks.directives._getCached(providerUri), opts);
return OAUTH3.hooks.directives.get(providerUri).then(function (directives) {
return OAUTH3._logoutHelper(directives, opts);
});
}
, _logoutHelper: function(directives, opts) {
, _logoutHelper: function(providerUri, directives, opts) {
var logoutReq = OAUTH3.urls.logout(
directives
, { client_id: (opts.client_id || opts.client_uri || OAUTH3.clientUri(OAUTH3._browser.window.location))
@ -843,7 +847,7 @@
return OAUTH3.PromiseA.reject(OAUTH3.error.parse(directives.issuer /*providerUri*/, params));
}
OAUTH3.hooks.session.clear();
OAUTH3.hooks.session.clear(providerUri);
return params;
});
}
@ -1390,9 +1394,10 @@
}
, login: function (opts) {
var me = this;
if (me.session()) {
return OAUTH3.hooks.session.get(me._identityProviderUri).then(function (session) {
if (session) {
me._session = true;
return OAUTH3.PromiseA.resolve(me.session());
return session;
}
opts = opts || {};
@ -1402,10 +1407,11 @@
me._session = true;
return session;
});
});
}
, session: function (session, id) {
if (!session) {
return JSON.parse(JSON.stringify(OAUTH3.hooks.session._getCached(this._identityProviderUri) || null));
return OAUTH3.hooks.session.get(this._identityProviderUri);
}
return OAUTH3.hooks.session.set(this._identityProviderUri, session, id);
}
@ -1414,29 +1420,37 @@
preq.client_uri = this._clientUri;
preq.client_id = this._clientUri;
preq.method = preq.method || 'GET';
if (this._session) {
preq.session = preq.session || this.session(); // OAUTH3.hooks.session._getCached(this._identityProviderUri);
}
// TODO maybe use a baseUrl from the directives file?
preq.url = OAUTH3.url.resolve(this._resourceProviderUri, preq.url);
if (preq.session || !this._session) {
return OAUTH3.request(preq, opts);
}
return this.session().then(function (session) {
preq.session = session;
return OAUTH3.request(preq, opts);
});
}
, logout: function (opts) {
this._session = false;
opts = opts || {};
return OAUTH3.hooks.session.get(this._identityProviderUri).then(function (session) {
opts.client_uri = this._clientUri;
opts.client_id = this._clientUri;
opts.session = OAUTH3.hooks.session._getCached(this._identityProviderUri);
opts.session = session;
return OAUTH3.logout(this._identityProviderUri, opts);
});
}
, api: function (api, opts) {
opts = opts || {};
return OAUTH3.hooks.session.get(this._identityProviderUri).then(function (session) {
opts.api = api;
opts.session = OAUTH3.hooks.session._getCached(this._identityProviderUri);
opts.session = session;
return OAUTH3.api(this._resourceProviderDirectives.api, opts);
});
}
, pkg: function (pkgname) {
var me = this;
@ -1450,17 +1464,19 @@
return OAUTH3.PromiseA.reject(new Error("No Package for '" + pkgname + "'"));
}
return OAUTH3.hooks.session.get(issuer).then(function (session) {
pkg = OAUTH3._pkgs[pkgname];
Object.keys(pkg).forEach(function (key) {
result[key] = function (opts) {
opts = opts || {};
opts.session = OAUTH3.hooks.session._getCached(issuer);
opts.session = session;
opts.audience = audience;
return pkg[key](opts);
};
});
return result;
});
}
};
result.setIssuer = result.setIdentityProvider;