1

I am using Microsoft.IdentityModel.Clients.ActiveDirectory NuGet and for an app I retrieve token like below code:

public async Task<IotHubClient> GetIotHubClient()
{
    var authContext = new AuthenticationContext(_configuration["IoTHub:Credentials:Authority"]);
    var credential = new ClientCredential(_configuration["IoTHub:Credentials:ClientId"], await _secretKeyReader.GetSecretValue("IotHubScalingAppKey"));
    var token = await authContext.AcquireTokenAsync(_configuration["IoTHub:Credentials:Resource"], credential);

    if (token == null) return null;

    var credentials = new TokenCredentials(token.AccessToken);
    var client = new IotHubClient(credentials)
    {
        SubscriptionId = _configuration["IoTHub:Credentials:SubscriptionId"]
    };

    return client;
}

Since the package Microsoft.IdentityModel.Clients.ActiveDirectory is deprecated, I'm trying to use the package Microsoft.Identity.Client, but the above method no longer works.

What's the way to get the token?

Florian
  • 1,019
  • 6
  • 22
user584018
  • 10,186
  • 15
  • 74
  • 160
  • You should look at other methods of getting the token, [here](https://learn.microsoft.com/en-us/dotnet/api/microsoft.identity.client.acquiretokensilentparameterbuilder?view=azure-dotnet), full list [here](https://learn.microsoft.com/en-us/dotnet/api/microsoft.identity.client?view=azure-dotnet) – Anand Sowmithiran Jan 12 '23 at 09:50
  • you should read this : [msal-net-migration](https://learn.microsoft.com/en-us/azure/active-directory/develop/msal-net-migration): – Mohammad Aghazadeh Jan 12 '23 at 10:11

0 Answers0