diff --git a/oauth3.core.js b/oauth3.core.js index fdd707b..d5f9ade 100644 --- a/oauth3.core.js +++ b/oauth3.core.js @@ -1,4 +1,4 @@ -/* global Promise */ +/ * global Promise */ ;(function (exports) { 'use strict'; @@ -294,7 +294,11 @@ } } , urls: { - discover: function (providerUri, opts) { + scope: function (directives, opts) { + var uri = directives.grants.url; + uri.replace("/:sub", ); + } + , discover: function (providerUri, opts) { if (!providerUri) { throw new Error("cannot discover without providerUri"); } @@ -658,9 +662,43 @@ } } } + , discoverGrants: function (providerUri, opts) { + if (!providerUri) { + throw new Error('oauth3.discoverGrants(providerUri, opts) received providerUri as :', providerUri); + } + + var opts = opts || {}; + var err; + if(!opts.sub && (!opts.token || !opts.token.sub)) { + err = new Error('We need a sub in order to discover grants for.'); + err.code = 'E_NO_SUB'; + throw err; + } + if(! + + + console.warn(!opts.scopes) { + var firstDo; + + if (directives && directives.issuer) { + firstDo = OAUTH3.PromiseA.resolve(directives); + } else { + firstDo = this.discover(providerUri, opts); + } + + return firstDo.then(function(directives) { + var grantPromises = []; + + + + return OAUTH3._disoverHelper(providerUri, "grants", opts); + }).then(function() { + }); + } + , discover: function (providerUri, opts) { if (!providerUri) { - throw new Error('oauth3.discover(providerUri, opts) received providerUri as ' + providerUri); + throw new Error('oauth3.discover(providerUri, opts) received providerUri as :', providerUri); } return OAUTH3.hooks.directives.get(providerUri).then(function (directives) { @@ -668,7 +706,7 @@ return directives; } - return OAUTH3._discoverHelper(providerUri, opts).then(function (directives) { + return OAUTH3._discoverHelper(providerUri, "directives", opts).then(function (directives) { directives.azp = directives.azp || OAUTH3.url.normalize(providerUri); directives.issuer = directives.issuer || OAUTH3.url.normalize(providerUri); directives.api = OAUTH3.url.normalize((directives.api||':hostname').replace(/:hostname/, OAUTH3.uri.normalize(directives.issuer) || OAUTH3.uri.normalize(providerUri))); @@ -677,8 +715,8 @@ }); }); } - , _discoverHelper: function(providerUri, opts) { - return OAUTH3._browser.discover(providerUri, opts); + , _discoverHelper: function(providerUri, type, opts) { + return OAUTH3._browser.discover(providerUri, type, opts); } , request: function (preq, opts) { function fetch() { @@ -859,7 +897,7 @@ , _browser: { window: 'undefined' !== typeof window ? window : null // TODO we don't need to include this if we're using jQuery or angular - , discover: function(providerUri, opts) { + , discover: function(providerUri, type, opts) { opts = opts || {}; providerUri = OAUTH3.url.normalize(providerUri);