简体   繁体   中英

Azure: Web Apps - List Application Settings from deployed nodejs app

I've deployed a nodeJs app to a Linux Azure AppService. Now I would like to list the server settings of that same app-service. Under the Identity tab I enabled the managed Identity for this AppService. In my NodeJs App I've tried the following:

const { DefaultAzureCredential } = require("@azure/identity");

const credential = new DefaultAzureCredential();

credential.getToken().then(token => {
  ...
});

I'm not really sure what this is doing, but I don't think it connects, because the getToken never resolves. Any suggestions what I'm missing here?

If you want to get server setting values inside of the app service, you can just try process.env.NODE_ENV as this doc indicated. Instead of calling Azure management API.

If you want to get server setting values outside of the app service, your code can't access server setting values directly, so you should call Azure management API. If you have some problem with DefaultAzureCredential , you can try ClientSecretCredential . Just try the code below:

const { ClientSecretCredential } = require("@azure/identity");

const fetch = require("node-fetch")

let  tenantId='';
let  clientID = '';
let clientSecret = '';

let subscriptionID = ''
let resourceGroup = ''
let appServiceName = ''

new ClientSecretCredential(tenantId,clientID,clientSecret).getToken(['https://management.azure.com/.default']).then(result=>{
    accessToken = result.token
    reqURL = `https://management.azure.com/subscriptions/${subscriptionID}/resourceGroups/${resourceGroup}/providers/Microsoft.Web/sites/${appServiceName}/config/appsettings/list?api-version=2019-08-01`
    fetch(reqURL, {
        method: 'post',
        headers: { 'Authorization': 'Bearer ' +  accessToken},
    })
    .then(res => res.json())
    .then(json => console.log(json));

})

Result:

在此处输入图像描述 在此处输入图像描述

For how to create an Azure AD app and assign a role to it so that it could have permission to call Azure mgmt APIs, see this doc .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM