I'm attempting to perform S2S authentication from a Dynamics 365 plugin, unsuccessfully so far. The following exception occurs:
System.TypeInitializationException: The type initializer for 'Microsoft.IdentityModel.Clients.ActiveDirectory.Authenticator' threw an exception
My understanding is that the exception is thrown at the time when IdentityModel dll gets loaded, not even during runtime. However, if that matters, here is what we are doing in code:
var clientCreds = new ClientCredential(clientId, secret);
AuthenticationContext authContext = new AuthenticationContext(authorityUri);
AuthenticationResult authResult = authContext.AcquireTokenAsync(resource, clientCreds).GetAwaiter().GetResult();
We are using the following packages:
The same code works in a console app. Any help/suggestions are very appreciated.