Skip to content

Commit

Permalink
#139: support setting SSO flag and FederationID on create/update
Browse files Browse the repository at this point in the history
  • Loading branch information
JoernBerkefeld committed Feb 16, 2023
1 parent caa9d72 commit b6866cc
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 3 deletions.
34 changes: 34 additions & 0 deletions lib/metadataTypes/AccountUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,40 @@ class AccountUser extends MetadataType {
metadata.Client = {
ID: this.buObject.mid,
};

if (metadata.SsoIdentity || metadata.SsoIdentities) {
const ssoIdentity = {};
if (metadata.SsoIdentity) {
// assume metadata.SsoIdentity is an object
ssoIdentity.IsActive = metadata.SsoIdentity.IsActive;
ssoIdentity.FederatedId = metadata.SsoIdentity.FederatedId;
delete metadata.SsoIdentity;
} else if (Array.isArray(metadata.SsoIdentities)) {
// be nice and allow SsoIdentities as an alternative if its an array of objects
ssoIdentity.IsActive = metadata.SsoIdentities[0].IsActive;
ssoIdentity.FederatedId = metadata.SsoIdentities[0].FederatedId;
} else if (
Array.isArray(metadata.SsoIdentities?.SsoIdentity) &&
metadata.SsoIdentities?.SsoIdentity.length
) {
// API-compliant format already provided; just use it
ssoIdentity.IsActive = metadata.SsoIdentities.SsoIdentity[0]?.IsActive;
ssoIdentity.FederatedId = metadata.SsoIdentities.SsoIdentity[0]?.FederatedId;
} else {
throw new TypeError(
'SsoIdentity should be an object with IsActive and FederatedId properties.'
);
}
// if SsoIdentity is set, assume this was on purpose and bring it
metadata.SsoIdentities = {
SsoIdentity: [
{
IsActive: ssoIdentity.IsActive,
FederatedId: ssoIdentity.FederatedId,
},
],
};
}
return metadata;
}
/**
Expand Down
23 changes: 20 additions & 3 deletions lib/metadataTypes/definitions/AccountUser.definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,26 @@ module.exports = {
skipValidation: false,
},
SsoIdentities: {
// not supported by API
isCreateable: false,
isUpdateable: false,
isCreateable: true,
isUpdateable: true,
retrieving: false, // retrieve not supported by API
template: false,
},
'SsoIdentities[]': {
isCreateable: true,
isUpdateable: true,
retrieving: false,
template: false,
},
'SsoIdentities[].IsActive': {
isCreateable: true,
isUpdateable: true,
retrieving: false,
template: false,
},
'SsoIdentities[].FederatedID': {
isCreateable: true,
isUpdateable: true,
retrieving: false,
template: false,
},
Expand Down

0 comments on commit b6866cc

Please sign in to comment.