From e9f8d06176888e608dde68f0d69e9a6bad815ea9 Mon Sep 17 00:00:00 2001 From: Luka Skukan Date: Tue, 20 Dec 2016 13:13:45 +0100 Subject: [PATCH 1/2] Add support for auto-expansion of application custom data --- lib/config.yml | 4 ++++ lib/helpers/get-application.js | 35 ++++++++++++++++++++++++++++++++++ lib/helpers/index.js | 3 ++- lib/stormpath.js | 2 +- 4 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 lib/helpers/get-application.js diff --git a/lib/config.yml b/lib/config.yml index f25ab415..656653ce 100644 --- a/lib/config.yml +++ b/lib/config.yml @@ -221,6 +221,10 @@ web: providerData: false tenant: false + application: + expand: + customData: true + # If the developer wants our integration to serve their Single Page # Application (SPA) in response to HTML requests for our default routes, # such as /login, then they will need to enable this feature and tell us diff --git a/lib/helpers/get-application.js b/lib/helpers/get-application.js new file mode 100644 index 00000000..727f1790 --- /dev/null +++ b/lib/helpers/get-application.js @@ -0,0 +1,35 @@ +'use strict'; + +/** + * @function + * @private + * + * @description + * Loads the application from a href, optionally expanding fields passed via the + * `expand` parameter. + * + * @param {String} appHref + * The HREF of the application to load. + * @param {Object} client + * The Stormpath client + * @param {Object} expand + * Definition of which objects to expand as an object of string-boolean pairs. + * @param {Function} callback + * The function to call when done. Called with {err, Application} + */ +module.exports = function getApplication(appHref, client, expand, callback) { + var appOptions = {}; + var expandOn = []; + + Object.keys(expand).forEach(function (field) { + if (expand[field]) { + expandOn.push(field); + } + }); + + if (expandOn) { + appOptions.expand = expandOn.join(','); + } + + return client.getApplication(appHref, appOptions, callback); +}; \ No newline at end of file diff --git a/lib/helpers/index.js b/lib/helpers/index.js index 69957ce7..0138b6c9 100644 --- a/lib/helpers/index.js +++ b/lib/helpers/index.js @@ -24,5 +24,6 @@ module.exports = { xsrfValidator: require('./xsrf-validator'), revokeToken: require('./revoke-token'), getFormViewModel: require('./get-form-view-model').default, - strippedAccountResponse: require('./stripped-account-response') + strippedAccountResponse: require('./stripped-account-response'), + getApplication: require('./get-application') }; diff --git a/lib/stormpath.js b/lib/stormpath.js index 839fbbc8..caa50147 100644 --- a/lib/stormpath.js +++ b/lib/stormpath.js @@ -211,7 +211,7 @@ module.exports.init = function (app, opts) { router.all(web.oauth2.uri, bodyParser.form(), stormpathMiddleware, controllers.getToken); } - client.getApplication(config.application.href, function (err, application) { + helpers.getApplication(config.application.href, client, web.application.expand, function (err, application) { if (err) { throw new Error('Cannot fetch application ' + config.application.href); } From 9e75792aa1cea3bf24f568d27ad9cfbc39c570e8 Mon Sep 17 00:00:00 2001 From: Luka Skukan Date: Tue, 20 Dec 2016 13:16:58 +0100 Subject: [PATCH 2/2] Default expansion options to false --- lib/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/config.yml b/lib/config.yml index 656653ce..e6954e16 100644 --- a/lib/config.yml +++ b/lib/config.yml @@ -223,7 +223,7 @@ web: application: expand: - customData: true + customData: false # If the developer wants our integration to serve their Single Page # Application (SPA) in response to HTML requests for our default routes,