For those using the Azure JavaScript SDK, you can use this snippet to get the Site Credentials (aka Publish Profile Credentials). I'm assuming you have an instance of WebSiteManagementClient and an implementation of streamToBuffer which converts a nodejs ReadableStream into a Buffer.
let credentialCreate = await webSiteManagementClient.webApps.listPublishingProfileXmlWithSecrets(
resourceGroupName, // The resource group the Function App is in
siteName, // i.e. the Function App name
{
format: 'FileZilla3'
}
)
let contentBuffer = await streamToBuffer(credentialCreate.readableStreamBody);
let credentialsAsXML = contentBuffer.toString();
And for a quick and dirty way to parse Host, User, and Pass...
let hostResults = credentialsAsXML.match(/<Host>(.+)<\/Host>/)
let userResults = credentialsAsXML.match(/<User>(.+)<\/User>/)
let passResults = credentialsAsXML.match(/<Pass(?: encoding="base64")?>(.+)<\/Pass>/)
let host = hostResults ? hostResults[1] : null;
let user = userResults ? userResults[1] : null;
let pass = passResults ? passResults[1] : null;
console.log(host, user, pass)
And finally, if you intend to get the "Profile Publishing Credentials" you'll need to further parse the User and Pass values.
// The "User" value in the XML is structured as: my-new-function3\$my-new-function3.
// The actual user that needs to be used in the Zip Endpoint is the last segment starting
// with the dollar sign
let ppcUser = user.replace(siteName + '\\', '');
// The "Pass" value in the XML is base64 encoded. We need to decode this before
// we use it on the Zip endpoint.
let ppcDecodedPass = Buffer.from(pass, 'base64').toString();