Reputation: 29129
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?
Upvotes: 1
Views: 531
Reputation: 12153
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.
Upvotes: 2