From 8961a4e51962a21690b5e68af3abaad24be8207c Mon Sep 17 00:00:00 2001 From: aj Date: Wed, 16 Aug 2017 21:44:36 +0000 Subject: [PATCH] separate client init from options init --- oauth3.core.js | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/oauth3.core.js b/oauth3.core.js index c003789..9cab6cb 100644 --- a/oauth3.core.js +++ b/oauth3.core.js @@ -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;