Skip to content
This repository was archived by the owner on Dec 12, 2018. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions lib/oauth/stormpath-social.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,6 @@ util.inherits(OAuthStormpathSocialAuthenticator, ScopeFactoryAuthenticator);
OAuthStormpathSocialAuthenticator.prototype.authenticate = function authenticate(authenticationRequest, callback) {
var application = this.application;

console.log('authenticationRequest',authenticationRequest);

if (typeof authenticationRequest !== 'object') {
throw new Error('The \'authenticationRequest\' parameter must be an object.');
}
Expand Down
36 changes: 17 additions & 19 deletions lib/resource/Application.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ var InstanceResource = require('./InstanceResource');
var OauthAccessTokenAuthenticator = require('../authc/OauthAccessTokenAuthenticator');
var OAuthBasicExchangeAuthenticator = require('../authc/OAuthBasicExchangeAuthenticator');
var PasswordResetToken = require('./PasswordResetToken');
var ExtractsAccountStoreMixin = require('./mixins/ExtractsAccountStoreMixin');
var errorMessages = require('../error/messages');
var utils = require('../utils');

Expand Down Expand Up @@ -44,6 +45,8 @@ function Application() {
}
utils.inherits(Application, InstanceResource);

utils.applyMixin(Application, ExtractsAccountStoreMixin);

/**
* Creates a URL which will redirect a user to your ID Site. The URL will look
* like `https://api.stormpath.com/v1/sso?jwtRequest=<token>`. Once the URL
Expand Down Expand Up @@ -1144,27 +1147,22 @@ Application.prototype.getAccountStoreMappings = function getAccountStoreMappings
};

/**
* Retrieves the {@link ApplicationAccountStoreMapping} that represents the link
* to the Application's default Account Store, which is the {@link Directory}
* Retrieves the application account store, which is the {@link Directory}
* that new accounts will be created in when using {@link
* Application#createAccount Application.createAccount()}.
*
* **Note**: This method is named incorrectly, it should be returning the {@link
* Directory} resource (not the {@link ApplicationAccountStoreMapping}). This
* will be fixed in version 1.0.0.
*
* @param {ExpansionOptions} [expansionOptions]
* For retrieving linked resources of the account store during this request.
*
* @param {Function} callback
* The function to call when the operation is complete. Will be called
* with the parameters (err, {@link ApplicationAccountStoreMapping}).
* with the parameters (err, {@link Directory}).
*
* @example
*
* application.getDefaultAccountStore({ expand: 'accountStore' }, function(err, applicationAccountStoreMapping) {
* application.getDefaultAccountStore(function(err, accountStore) {
* if (!err) {
* console.log(applicationAccountStoreMapping.accountStore.name);
* console.log(accountStore.name);
* }
* });
*/
Expand All @@ -1175,7 +1173,9 @@ Application.prototype.getDefaultAccountStore = function getDefaultAccountStore(/
return args.callback();
}

return this.dataStore.getResource(this.defaultAccountStoreMapping.href, args.options, ApplicationAccountStoreMapping, args.callback);
return this.getLinkedAccountStore(
this.defaultAccountStoreMapping.href, args.options, ApplicationAccountStoreMapping, args.callback
);
};

/**
Expand Down Expand Up @@ -1257,27 +1257,23 @@ Application.prototype.setDefaultAccountStore = function setDefaultAccountStore(s
};

/**
* Retrieves the {@link ApplicationAccountStoreMapping} that represents the link
* to the Application's default group store, which is the {@link Directory}
* Retrieves the application group store, which is the {@link Directory}
* that new groups will be created in when using {@link Application#createGroup
* Application.createGroup()}.
*
* **Note**: This method is named incorrectly, it should be returning the {@link
* Directory} resource (not the {@link ApplicationAccountStoreMapping}). This
* will be fixed in version 1.0.0.
*
* @param {ExpansionOptions} [expansionOptions]
* For retrieving linked resources of the account store during this request.
*
* @param {Function} callback
* The function to call when the operation is complete. Will be called
* with the parameters (err, {@link ApplicationAccountStoreMapping}).
* with the parameters (err, {@link Directory}).
*
* @example
*
* application.getDefaultGroupStore({ expand: 'accountStore' }, function(err, applicationAccountStoreMapping) {
* application.getDefaultGroupStore( function(err, groupStore) {
* if (!err) {
* console.log(applicationAccountStoreMapping.accountStore.name);
* console.log(groupStore.name);
* }
* });
*/
Expand All @@ -1288,7 +1284,9 @@ Application.prototype.getDefaultGroupStore = function getDefaultGroupStore(/* [o
return args.callback();
}

return this.dataStore.getResource(this.defaultGroupStoreMapping.href, args.options, ApplicationAccountStoreMapping, args.callback);
return this.getLinkedAccountStore(
this.defaultGroupStoreMapping.href, args.options, ApplicationAccountStoreMapping, args.callback
);
};

/**
Expand Down
38 changes: 17 additions & 21 deletions lib/resource/Organization.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var Application = require('./Application');
var CustomData = require('./CustomData');
var IdSiteModel = require('./IdSiteModel');
var OrganizationAccountStoreMapping = require('./OrganizationAccountStoreMapping');
var ExtractsAccountStoreMixin = require('./mixins/ExtractsAccountStoreMixin');

/**
* @class Organization
Expand Down Expand Up @@ -38,6 +39,7 @@ function Organization() {
}

utils.inherits(Organization, require('./InstanceResource'));
utils.applyMixin(Organization, ExtractsAccountStoreMixin);

/**
* Creates an {@link Account} in the organization's default account store.
Expand Down Expand Up @@ -203,7 +205,9 @@ Organization.prototype.getDefaultAccountStoreMapping = function getDefaultAccoun
return args.callback();
}

return this.dataStore.getResource(this.defaultAccountStoreMapping.href, args.options, OrganizationAccountStoreMapping, args.callback);
return this.getLinkedAccountStore(
this.defaultAccountStoreMapping.href, args.options, OrganizationAccountStoreMapping, args.callback
);
};

/**
Expand Down Expand Up @@ -262,17 +266,13 @@ Organization.prototype.getDefaultGroupStoreMapping = function getDefaultGroupSto
Organization.prototype.getDefaultAccountStore = function getDefaultAccountStore(/* [options,] callback */) {
var args = utils.resolveArgs(arguments, ['options', 'callback'], true);

return this.getDefaultAccountStoreMapping({ expand: 'accountStore' }, function (err, organizationAccountStoreMapping) {
if (err) {
return args.callback(err);
}

if (!organizationAccountStoreMapping) {
return args.callback(null, null);
}
if (!this.defaultAccountStoreMapping) {
return args.callback();
}

organizationAccountStoreMapping.getAccountStore(args.options, args.callback);
});
return this.getLinkedAccountStore(
this.defaultAccountStoreMapping.href, args.options, OrganizationAccountStoreMapping, args.callback
);
};

/**
Expand All @@ -299,17 +299,13 @@ Organization.prototype.getDefaultAccountStore = function getDefaultAccountStore(
Organization.prototype.getDefaultGroupStore = function getDefaultGroupStore(/* [options,] callback */) {
var args = utils.resolveArgs(arguments, ['options', 'callback'], true);

return this.getDefaultGroupStoreMapping({ expand: 'accountStore' }, function (err, organizationAccountStoreMapping) {
if (err) {
return args.callback(err);
}

if (!organizationAccountStoreMapping) {
return args.callback(null, null);
}
if (!this.defaultGroupStoreMapping) {
return args.callback();
}

organizationAccountStoreMapping.getAccountStore(args.options, args.callback);
});
return this.getLinkedAccountStore(
this.defaultGroupStoreMapping.href, args.options, OrganizationAccountStoreMapping, args.callback
);
};

/**
Expand Down
21 changes: 21 additions & 0 deletions lib/resource/mixins/ExtractsAccountStoreMixin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
function getLinkedAccountStore(href, opts, Ctor, callback) {
var linkOpts = {expand: 'accountStore'};

return this.dataStore.getResource(href, linkOpts, Ctor, function(err, storeLink) {
if (err) {
return callback(err);
}

if (!storeLink || !storeLink.accountStore) {
return callback();
}

return storeLink.getAccountStore(opts, callback);
});
}

var ExtractsAccountStoreMixin = {
getLinkedAccountStore: getLinkedAccountStore
};

module.exports = ExtractsAccountStoreMixin;
8 changes: 1 addition & 7 deletions test/it/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,7 @@ function fakeDirectory(){
* @param {Function} callback - A callback to run when done.
*/
function getDefaultAccountStore(application,done){
application.getDefaultAccountStore(function(err,accountStoreMapping){
if(err){
done(err);
}else{
accountStoreMapping.getAccountStore(done);
}
});
application.getDefaultAccountStore(done);
}

/**
Expand Down
38 changes: 20 additions & 18 deletions test/sp.resource.application_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -959,34 +959,35 @@ describe('Resources: ', function () {
describe('get default account store', function () {
function getDefaultAccountStore(data) {
return function () {
var appObj, asmObj, app, asm;
var appObj, asmObj, app, store, storeObj;
before(function (done) {
// assert
asmObj = {href: '/account/store/mapping/href', name: 'asm name'};
asmObj = {href: '/account/store/mapping/href', accountStore: {href: '/account/store/directories/href'}, name: 'asm name'};
storeObj = {href: 'account/store/directories/href'};
appObj = {defaultAccountStoreMapping: {href: asmObj.href}};
app = new Application(appObj, dataStore);

nock(u.BASE_URL).get(u.v1(asmObj.href)).reply(200, asmObj);
nock(u.BASE_URL).get(u.v1(asmObj.href + '?expand=accountStore')).reply(200, asmObj);
nock(u.BASE_URL).get(u.v1(asmObj.accountStore.href)).reply(200, storeObj);

var args = [];
if (data) {
args.push(data);
}
args.push(function cb(err, mapping) {
asm = mapping;
args.push(function cb(err, accStore) {
store = accStore;
done();
});

// act
app.getDefaultAccountStore.apply(app, args);
});
it('should get default account store mapping data', function () {
asm.href.should.be.equal(asm.href);
asm.name.should.be.equal(asm.name);
it('should get default account store data', function () {
store.href.should.be.equal(store.href);
});

it('should be an instance of AccountStoreMapping', function () {
asm.should.be.an.instanceOf(AccountStoreMapping);
it('should be an instance of Directory', function () {
store.should.be.an.instanceOf(Directory);
});
};
}
Expand Down Expand Up @@ -1064,34 +1065,35 @@ describe('Resources: ', function () {
describe('get default group store', function () {
function getDefaultGroupStore(data) {
return function () {
var appObj, asmObj, app, asm;
var appObj, asmObj, app, store, storeObj;
before(function (done) {
// assert
asmObj = {href: '/account/store/mapping/href', name: 'asm name'};
asmObj = {href: '/account/store/mapping/href', name: 'asm name', accountStore: {href: '/account/store/directories/href'}};
storeObj = {href: '/account/store/directories/href'};
appObj = {defaultGroupStoreMapping: {href: asmObj.href}};
app = new Application(appObj, dataStore);

nock(u.BASE_URL).get(u.v1(asmObj.href)).reply(200, asmObj);
nock(u.BASE_URL).get(u.v1(asmObj.href + '?expand=accountStore')).reply(200, asmObj);
nock(u.BASE_URL).get(u.v1(asmObj.accountStore.href)).reply(200, storeObj);

var args = [];
if (data) {
args.push(data);
}
args.push(function cb(err, mapping) {
asm = mapping;
args.push(function cb(err, groupStore) {
store = groupStore;
done();
});

// act
app.getDefaultGroupStore.apply(app, args);
});
it('should get default group store mapping data', function () {
asm.href.should.be.equal(asm.href);
asm.name.should.be.equal(asm.name);
store.href.should.be.equal(store.href);
});

it('should be an instance of AccountStoreMapping', function () {
asm.should.be.an.instanceOf(AccountStoreMapping);
store.should.be.an.instanceOf(Directory);
});
};
}
Expand Down
Loading