From 39c0c775ed64406f3c7114e10667a1ac51888fe0 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Sat, 25 Nov 2017 09:10:54 +0000 Subject: [PATCH] get issuer via rpc --- oauth3.core.js | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/oauth3.core.js b/oauth3.core.js index 0159994..d7e973c 100644 --- a/oauth3.core.js +++ b/oauth3.core.js @@ -747,6 +747,20 @@ */ return OAUTH3._browser.request(preq, opts); } + , issuer: function (opts) { + if (!opts) { opts = {}; } + + // TODO this will default to browserlogin.org + var broker = opts.broker || 'https://broker.oauth3.org'; + + opts._rpc = "broker"; + opts._scheme = "localstorage:"; + opts._pathname = "issuer"; + + return OAUTH3._rpcHelper(broker, opts).then(function(issuer) { + return issuer; + }); + } , implicitGrant: function (directives, opts) { var promise; var providerUri = directives.azp || directives.issuer || directives; @@ -923,13 +937,13 @@ } } - if (!(opts.client_id || opts.client_uri).match(OAUTH3._browser.window.location.hostname)) { + if (!(opts.client_id || opts.client_uri || '').match(OAUTH3._browser.window.location.hostname)) { console.warn("It looks like your client_id doesn't match your current window..." + " this probably won't end well"); console.warn(opts.client_id || opts.client_uri, OAUTH3._browser.window.location.hostname); } - var discReq = OAUTH3.urls.rpc( + var discReq = OAUTH3.urls[opts._rpc || 'rpc']( providerUri , { client_id: (opts.client_id || opts.client_uri || OAUTH3.clientUri(OAUTH3._browser.window.location)) , windowType: opts.broker && opts.windowType || 'background' @@ -971,7 +985,14 @@ } // TODO params should have response_type indicating json, binary, etc - var result = JSON.parse(OAUTH3._base64.decodeUrlSafe(params.data || params.result || params.directives)); + var result; + try { + result = JSON.parse(OAUTH3._base64.decodeUrlSafe(params.data || params.result || params.directives)); + } catch(e) { + result = params.data || params.result; + } + + console.log('result:', result); // caller will call OAUTH3.hooks.directives.set(providerUri, directives); return result; });