From f7a7703b49496eecdbf6240002a65608904c56e4 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Mon, 27 Feb 2017 18:19:01 -0700 Subject: [PATCH] bugfix opts.staletime, support domains --- oauth3.core.js | 19 +++++++++++++++++-- oauth3.domains.js | 19 +++++++++++++++++++ oauth3.issuer.js | 2 +- oauth3.ng.js | 2 +- 4 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 oauth3.domains.js diff --git a/oauth3.core.js b/oauth3.core.js index 3396a65..ac9249e 100644 --- a/oauth3.core.js +++ b/oauth3.core.js @@ -458,6 +458,7 @@ return OAUTH3.PromiseA.resolve(OAUTH3.hooks.session.set(providerUri, oldSession)); } , check: function (preq, opts) { + opts = opts || {}; if (!preq.session) { return OAUTH3.PromiseA.resolve(null); } @@ -954,6 +955,13 @@ ); } } + , api: function (providerUri, opts) { + if (!OAUTH3.api[opts.api]) { + throw new Error("No API for '" + providerUri + "'"); + } + + return OAUTH3.api[opts.api](providerUri, opts); + } }; OAUTH3.login = OAUTH3.implicitGrant; @@ -1031,7 +1039,8 @@ , session: function () { return JSON.parse(JSON.stringify(OAUTH3.hooks.session._getCached(this._providerUri))); } - , request: function (preq) { + , request: function (preq, opts) { + opts = opts || {}; preq.client_uri = this._clientUri; preq.client_id = this._clientUri; preq.method = preq.method || 'GET'; @@ -1040,7 +1049,7 @@ } // TODO maybe use a baseUrl from the directives file? preq.url = OAUTH3.url.resolve(this._providerUri, preq.url); - return OAUTH3.request(preq); + return OAUTH3.request(preq, opts); } , logout: function (opts) { opts = opts || {}; @@ -1050,6 +1059,12 @@ return OAUTH3.logout(this._providerUri, opts); } + , api: function (api, opts) { + opts = opts || {}; + opts.api = api; + opts.session = OAUTH3.hooks.session._getCached(this._providerUri); + OAUTH3.api(this._providerUri, opts); + } }; result.authenticate = result.login; result.authorize = result.login; diff --git a/oauth3.domains.js b/oauth3.domains.js new file mode 100644 index 0000000..d9320ff --- /dev/null +++ b/oauth3.domains.js @@ -0,0 +1,19 @@ +;(function (exports) { +'use strict'; + +var OAUTH3 = exports.OAUTH3 = exports.OAUTH3 || require('./oauth3.core.js').OAUTH3; + +OAUTH3.api['domains.list'] = function (providerUri, opts) { + var session = opts.session; + + return OAUTH3.request({ + method: 'GET' + , url: OAUTH3.url.normalize(providerUri) + + '/api/com.daplie.domains/accounts/' + session.token.sub + '/registrations' + , session: session + }).then(function (res) { + return res.data; + }); +}; + +}('undefined' !== typeof exports ? exports : window)); diff --git a/oauth3.issuer.js b/oauth3.issuer.js index 80e2462..7bd137a 100644 --- a/oauth3.issuer.js +++ b/oauth3.issuer.js @@ -1,7 +1,7 @@ ;(function (exports) { 'use strict'; -var OAUTH3 = exports.OAUTH3 = exports.OAUTH3 || require('./oauth3.implicit.js').OAUTH3; +var OAUTH3 = exports.OAUTH3 = exports.OAUTH3 || require('./oauth3.core.js').OAUTH3; OAUTH3.query.parse = function (search) { // parse a query or a hash diff --git a/oauth3.ng.js b/oauth3.ng.js index b5fdefb..97f0b96 100644 --- a/oauth3.ng.js +++ b/oauth3.ng.js @@ -2,7 +2,7 @@ 'use strict'; angular - .module('oauth3', []) + .module('org.oauth3', []) .service('Oauth3', [ '$timeout' , '$q'