Microsoft-authentication-library-for-dotnet: 'ClientApplicationBase.Users' is obsolete: 'Use GetAccountsAsync instead

Created on 27 Sep 2018  路  3Comments  路  Source: AzureAD/microsoft-authentication-library-for-dotnet


Hi, please helpme with the next problem


I'm trying to get GetAccessToken but i have a problem with the next line, I can not get the users

AuthenticationResult result = await cca.AcquireTokenSilentAsync (scopes, cca.Users.First());

The problema says

'ClientApplicationBase.Users' is obsolete: 'Use GetAccountsAsync instead

question

All 3 comments

Yes, the API has changed in MSAL 2, it uses the concept of Account instead of User. But changes are minimal, you just change to:

var accounts = await cca.GetAccountsAsync();
await cca.AcquireTokenSilentAsync(scopes, accounts.FirstOrDefault());

I previously had:

try
{
     _AuthResult = await PublicClientApp.AcquireTokenSilentAsync(_Scopes, PublicClientApp.Users.FirstOrDefault());
}

So using your example, you no longer assign a result. Please advise.

In my case I am now using:

    var accounts = await PublicClientApp.GetAccountsAsync();
    _AuthResult = await PublicClientApp.AcquireTokenSilentAsync(_Scopes, accounts.FirstOrDefault());

@ajtruckle : Bogdan meant

try
{
 _AuthResult = await  cca.AcquireTokenSilentAsync(scopes, accounts.FirstOrDefault());
}
Was this page helpful?
0 / 5 - 0 ratings