Currently I am new to concept MSI with API. I have an Azure App Service consist of Web Job and Authenticated Web API deployed. Also I do have Azure AD Application used for authentication. But I am using AuthenticationContext and ClientCredentical to acquire Token which is further used in Authentication Header value. Now I have to remove ClientCredentical and add MSI to get authentication token or to authenticate the web api. Here I add some sample code I am using.
var authContext = new AuthenticationContext(authority);
var clientCred = new ClientCredentical(clientID, clientKey);
var token = authContext.AcquireTokenAsync(clientId, clientCred).Result.Token;
httpClient.DefaultRequestHeaders.Autheorization = new AuthenticationHeaderValue('Bearer',token);
I had been through some of the offical documemts but couldn't get it clearly. I tried using DefaultAzureCredential
as well.
new DefaultAzureCredntial().GetTokenAsync(scope).Result.Token
I have to implement some solution which could work locally as well as in deployed version also. DefaultAzureCredential
Changes the access method as per environment but still that is also not working for visual studio.