Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function createServicePrincipal(credentials, tenantId, subscriptionId) {
const credOptions = {
domain: tenantId,
tokenAudience: "graph",
username: credentials.username,
tokenCache: credentials.tokenCache,
environment: credentials.environment
};
const credsForGraph = new azureRest.DeviceTokenCredentials(credOptions);
const graphClient = new graph(credsForGraph, tenantId);
const spPass = azureRest.generateUuid();
const spName = `http://${azureRest.generateUuid()}.azjs.com`;
const appOptions = {
availableToOtherTenants: false,
displayName: "azjs",
homepage: spName,
identifierUris: [spName],
passwordCredentials: [{
startDate: moment().toISOString(),
endDate: moment().add(1, "month").toISOString(),
keyId: azureRest.generateUuid(),
value: spPass
}]
};
function createCredentials(baseCredentials, tenantId, graphToken = false) {
const credentialOptions = {
domain: tenantId,
username: baseCredentials.username,
tokenCache: baseCredentials.tokenCache,
environment: baseCredentials.environment
};
if (graphToken) {
credentialOptions.tokenAudience = "graph";
}
return new azure.DeviceTokenCredentials(credentialOptions);
}