Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return __awaiter(this, void 0, void 0, function* () {
// For now the interactive user needs to explicitly be assigned
// the role of a constributor/owner even if the user is a subscription owner.
// azure role assignment create -o contributor --scope /subscriptions//resourceGroups//providers/Microsoft.EventHub/namespaces/ --signInName
const credentials = yield msrestAzure.interactiveLogin({ tokenAudience: lib_1.aadEventHubsAudience });
const client = lib_1.EventHubClient.createFromAadTokenCredentials(address, path, credentials);
yield client.send({ body: "Hello awesome world!!" }, "0");
const datas = yield client.receiveBatch("0", 2, 5, { eventPosition: lib_1.EventPosition.fromEnqueuedTime(Date.now()) });
console.log(">>> EventDataObjects: ", datas);
yield client.close();
});
}
return __awaiter(this, void 0, void 0, function* () {
// For now the interactive user needs to explicitly be assigned
// the role of a constributor/owner even if the user is a subscription owner.
// azure role assignment create -o contributor --scope /subscriptions//resourceGroups//providers/Microsoft.EventHub/namespaces/ --signInName
const credentials = yield msrestAzure.interactiveLogin({ tokenAudience: azure_event_hubs_1.aadEventHubsAudience });
const client = azure_event_hubs_1.EventHubClient.createFromAadTokenCredentials(address, path, credentials);
yield client.send({ body: "Hello awesome world!!" }, "0");
const datas = yield client.receiveBatch("0", 2, 5, { eventPosition: azure_event_hubs_1.EventPosition.fromEnqueuedTime(Date.now()) });
console.log(">>> EventDataObjects: ", datas);
yield client.close();
});
}
const userCodeResponseLogger = message => {
// Parse out the device code and copy it to the clipboard.
const [code] = message.match(/[A-Z0-9]{9,}/);
require("copy-paste").copy(code);
const newMessage = `Open a browser to ${INTERACTIVE_LOGIN_URL} and provide the following code (which is copied to your clipboard!) to complete the login process: ${code}`;
interactiveLoginHandler
? interactiveLoginHandler(code, newMessage)
: console.log(newMessage);
if (!suppressBrowser) {
require("opn")(INTERACTIVE_LOGIN_URL, { wait: false });
}
};
azure.interactiveLogin(
{
clientId: serviceClientId,
domain: serviceTenantId,
userCodeResponseLogger
},
handle()
);
}
});
var codeCopied = message.substring(message.indexOf(enterCodeString)
+ enterCodeString.length).replace(authString, '');
cp.copy(codeCopied);
// show the user the friendly message
vscode.window.showInformationMessage(
signInMessage.replace('{0}', codeCopied), {
title: loginButtonLabel
}).then(function (btn) {
if (btn && btn.title == loginButtonLabel) {
open(getUrls(message)[0]);
}
});
}
msRestAzure.interactiveLogin(options, function (err, credentials, subscriptions) {
state.credentials = credentials;
state.subscriptions = subscriptions;
if (state.subscriptions.length > 0) {
ux.showSubscriptionStatusBarButton();
ux.showSelectRegionStatusBarButton();
for (var i = 0; i < state.subscriptions.length; i++) {
state.subscriptionIds.push(state.subscriptions[i].id);
state.subscriptionNames.push(state.subscriptions[i].name + ' (' + state.subscriptions[i].id + ')');
}
credentials.retrieveTokenFromCache(function (notUsed, tokenType, accessToken) {
state.selectedSubscriptionId = state.subscriptions[0].id;
state.accessToken = accessToken;
vscode.window.showInformationMessage(loggedInMessage);
await AzureMethods.forEachSite(this.sites, async (site) => {
const currentSite = site;
const { servicePrincipal, tenantId, subscriptionId } = currentSite;
let credentials;
/* Retrieve credential from MS API, uses service principal when available
or otherwise requests an interactive login */
if (servicePrincipal !== undefined) {
const { appId, secret } = servicePrincipal;
winston.info(`${currentSite.uniqueName}: Authenticating with service principal`);
credentials = await msRest.loginWithServicePrincipalSecret(appId, secret, tenantId);
} else {
winston.info(`${currentSite.uniqueName}: Authenticating with interactive login...`);
credentials = await msRest.interactiveLogin({ domain: tenantId });
}
// Initialise Azure SDK using MS credential
winston.debug(`${currentSite.uniqueName}: completed Azure authentication`);
currentSite.azureSdk = new AzureSdk(credentials, subscriptionId).webApps;
});
}
function loginInteractively() {
const userCodeResponseLogger = (message) => {
const [code] = message.match(/[A-Z0-9]{7,}/);
copy(code);
log(green`Login to your Azure account in order to continue. The following device code has been copied to your clipboard and can be pasted into the launched browser: ${code}`);
opn("https://aka.ms/devicelogin");
};
interactive = true;
azureRest.interactiveLogin({ userCodeResponseLogger }, resolvePromise);
}