okta-mcp-server
Version:
Model Context Protocol (MCP) server for Okta API operations with support for bulk operations and caching
261 lines • 9.65 kB
JavaScript
import { faker } from '@faker-js/faker';
export class AppGenerator {
faker;
statusDistribution;
appTypes;
generatedCount = 0;
generatedLabels = new Set();
constructor(options = {}) {
this.faker = faker;
if (options.seed) {
this.faker.seed(options.seed);
}
this.statusDistribution = options.statusDistribution || {
ACTIVE: 0.9,
INACTIVE: 0.1,
};
this.appTypes = options.appTypes || [
{
name: 'salesforce',
label: 'Salesforce',
signOnMode: 'SAML_2_0',
features: ['PUSH_GROUPS', 'PUSH_NEW_USERS', 'PUSH_USER_DEACTIVATION', 'IMPORT_NEW_USERS'],
},
{
name: 'office365',
label: 'Office 365',
signOnMode: 'WS_FEDERATION',
features: [
'PUSH_GROUPS',
'PUSH_NEW_USERS',
'PUSH_USER_DEACTIVATION',
'IMPORT_NEW_USERS',
'PUSH_PASSWORD_UPDATES',
],
},
{
name: 'aws',
label: 'AWS Single Sign-on',
signOnMode: 'SAML_2_0',
features: ['PUSH_GROUPS', 'GROUP_PUSH'],
},
{
name: 'google',
label: 'Google Workspace',
signOnMode: 'SAML_2_0',
features: ['PUSH_GROUPS', 'PUSH_NEW_USERS', 'PUSH_USER_DEACTIVATION', 'IMPORT_NEW_USERS'],
},
{
name: 'slack',
label: 'Slack',
signOnMode: 'SAML_2_0',
features: ['PUSH_GROUPS', 'PUSH_NEW_USERS'],
},
{
name: 'github',
label: 'GitHub Enterprise',
signOnMode: 'SAML_2_0',
features: ['PUSH_GROUPS'],
},
{
name: 'jira',
label: 'Jira',
signOnMode: 'SAML_2_0',
features: ['PUSH_GROUPS', 'PUSH_NEW_USERS', 'IMPORT_NEW_USERS'],
},
{
name: 'zoom',
label: 'Zoom',
signOnMode: 'SAML_2_0',
features: ['PUSH_NEW_USERS', 'PUSH_USER_DEACTIVATION'],
},
{
name: 'box',
label: 'Box',
signOnMode: 'SAML_2_0',
features: ['PUSH_GROUPS', 'PUSH_NEW_USERS', 'PUSH_USER_DEACTIVATION'],
},
{
name: 'custom_saml',
label: 'Custom SAML App',
signOnMode: 'SAML_2_0',
features: [],
},
{
name: 'custom_oidc',
label: 'Custom OIDC App',
signOnMode: 'OPENID_CONNECT',
features: ['OAUTH2_SCOPE_CONSENT_GRANT'],
},
{
name: 'bookmark',
label: 'Bookmark App',
signOnMode: 'BOOKMARK',
features: [],
},
];
}
generate() {
this.generatedCount++;
const id = `0oa${this.faker.string.alphanumeric(17)}`;
const appType = this.faker.helpers.arrayElement(this.appTypes);
const created = this.faker.date.past({ years: 2 });
const lastUpdated = this.faker.date.between({ from: created, to: new Date() });
const status = this.selectStatus();
const label = this.generateUniqueLabel(appType);
const app = {
id,
name: appType.name,
label,
status,
lastUpdated: lastUpdated.toISOString(),
created: created.toISOString(),
features: [...appType.features],
signOnMode: appType.signOnMode,
};
// Add additional properties based on app type
this.addAppSpecificProperties(app, appType);
return app;
}
generateBatch(count) {
return Array.from({ length: count }, () => this.generate());
}
selectStatus() {
const random = this.faker.number.float({ min: 0, max: 1 });
let cumulative = 0;
for (const [status, probability] of Object.entries(this.statusDistribution)) {
cumulative += probability;
if (random <= cumulative) {
return status;
}
}
return 'ACTIVE';
}
generateUniqueLabel(appType) {
let label;
let attempts = 0;
const maxAttempts = 100;
do {
if (appType.label.includes('Custom')) {
// For custom apps, generate unique names
const prefix = this.faker.helpers.arrayElement([
'Internal',
'External',
'Partner',
'Customer',
'Employee',
]);
const suffix = this.faker.helpers.arrayElement([
'Portal',
'Dashboard',
'System',
'Platform',
'Service',
'Application',
]);
label = `${prefix} ${suffix}`;
}
else {
// For standard apps, optionally add environment suffix
label = appType.label;
if (this.faker.datatype.boolean({ probability: 0.4 })) {
const env = this.faker.helpers.arrayElement(['Production', 'Staging', 'Dev', 'Test']);
label = `${label} - ${env}`;
}
}
attempts++;
if (attempts >= maxAttempts) {
label = `${label}_${this.faker.string.alphanumeric(6)}`;
break;
}
} while (this.generatedLabels.has(label));
this.generatedLabels.add(label);
return label;
}
addAppSpecificProperties(app, _appType) {
// Add common properties
app['accessibility'] = {
selfService: this.faker.datatype.boolean({ probability: 0.7 }),
errorRedirectUrl: null,
loginRedirectUrl: null,
};
app['visibility'] = {
autoSubmitToolbar: false,
hide: {
iOS: false,
web: false,
},
appLinks: {
mainLink: this.faker.datatype.boolean({ probability: 0.8 }),
},
};
// Add sign-on mode specific properties
switch (app.signOnMode) {
case 'SAML_2_0':
app['settings'] = {
signOn: {
defaultRelayState: '',
ssoAcsUrl: `https://${this.faker.internet.domainName()}/sso/saml`,
idpIssuer: `http://www.okta.com/\${org.externalKey}`,
audience: `https://${this.faker.internet.domainName()}`,
recipient: `https://${this.faker.internet.domainName()}/sso/saml`,
destination: `https://${this.faker.internet.domainName()}/sso/saml`,
subjectNameIdTemplate: '${user.userName}',
subjectNameIdFormat: 'urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress',
responseSigned: true,
assertionSigned: true,
signatureAlgorithm: 'RSA_SHA256',
digestAlgorithm: 'SHA256',
honorForceAuthn: true,
authnContextClassRef: 'urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport',
},
};
break;
case 'OPENID_CONNECT':
app['settings'] = {
oauthClient: {
clientUri: `https://${this.faker.internet.domainName()}`,
logoUri: null,
redirectUris: [
`https://${this.faker.internet.domainName()}/callback`,
`https://${this.faker.internet.domainName()}/oauth/callback`,
],
responseTypes: ['code'],
grantTypes: ['authorization_code', 'refresh_token'],
applicationType: 'web',
consentMethod: 'REQUIRED',
},
};
app['credentials'] = {
oauthClient: {
clientId: this.faker.string.alphanumeric(20),
autoKeyRotation: true,
tokenEndpointAuthMethod: 'client_secret_basic',
},
};
break;
case 'BOOKMARK':
app['settings'] = {
app: {
requestIntegration: false,
url: `https://${this.faker.internet.domainName()}`,
},
};
break;
}
// Add some random additional properties
if (this.faker.datatype.boolean({ probability: 0.3 })) {
app['licensing'] = {
seatCount: this.faker.number.int({ min: 10, max: 1000 }),
};
}
}
reset() {
this.generatedCount = 0;
this.generatedLabels.clear();
}
getGeneratedCount() {
return this.generatedCount;
}
}
//# sourceMappingURL=app-generator.js.map