separate client init from options init

This commit is contained in:
aj 2017-08-16 21:44:36 +00:00
parent 9a7aa3261f
commit 8961a4e519
1 changed files with 13 additions and 9 deletions

View File

@ -1159,6 +1159,13 @@
}
}
}
, _initClient: function (location/*, opts*/) {
var me = this;
return OAUTH3.discover(me._clientUri, { client_id: me._clientUri }).then(function (clientDirectives) {
me._clientDirectives = clientDirectives;
return clientDirectives;
});
}
, init: function (location/*, opts*/) {
var me = this;
var p1 = OAUTH3.PromiseA.resolve();
@ -1168,25 +1175,22 @@
if (me._identityProviderUri) {
// returns directives
p1 = OAUTH3.discover(me._identityProviderUri, { client_id: this._clientUri });
p1 = me.setIssuer(me._identityProviderUri);
}
if (me._resourceProviderUri) {
// returns directives
p2 = OAUTH3.discover(me._resourceProviderUri, { client_id: this._clientUri });
p2 = me.setAudience(me._resourceProviderUri);
}
return p1.then(function () {
return p2.then(function () {
return OAUTH3.discover(me._clientUri, { client_id: me._clientUri }).then(function (clientDirectives) {
me._clientDirectives = clientDirectives;
return clientDirectives;
});
return me._initClient();
});
});
}
, setProvider: function (providerUri) {
var me = this;
return me.init().then(function () {
return me._initClient().then(function () {
return me.setIdentityProvider(providerUri).then(function () {
// TODO how to say "Use xyz.com for org.oauth3.domains, but abc.com for org.oauth3.dns"?
return me.setResourceProvider(providerUri);
@ -1196,7 +1200,7 @@
, setIdentityProvider: function (providerUri) {
var me = this;
me._identityProviderUri = providerUri;
return me.init().then(function () {
return me._initClient().then(function () {
// this should be synchronous the second time around
return OAUTH3.discover(me._identityProviderUri, { client_id: me._clientUri }).then(function (directives) {
me._identityProviderDirectives = directives;
@ -1207,7 +1211,7 @@
, setResourceProvider: function (providerUri) {
var me = this;
me._resourceProviderUri = providerUri;
return me.init().then(function () {
return me._initClient().then(function () {
// this should be synchronous the second time around
return OAUTH3.discover(me._resourceProviderUri, { client_id: me._clientUri }).then(function (directives) {
me._resourceProviderDirectives = directives;