对于某些项目,Windows Azure密钥保管库广告身份验证失败

问题描述:

我们正在使用azure密钥保管库来保护我们的azure存储blob加密。 This是我遵循的教程,以使其发挥作用。对于某些项目,Windows Azure密钥保管库广告身份验证失败

我开发了一个示例应用程序和用于加密blob的包装库。它在示例应用程序中运行良好。但在引用包装项目后的实际软件,当应用程序请求发生异常的原因,

private async Task<string> GetToken(string authority, string resource, string scope) 
    { 
     var authContext = new AuthenticationContext(authority); 

     ClientCredential clientCred = new ClientCredential(ADClientID, ADClientSecret); 
     AuthenticationResult result = await authContext.AcquireTokenAsync(resource, clientCred); 

     if (result == null) 
      throw new InvalidOperationException("Failed to obtain the JWT token"); 

     return result.AccessToken; 
    } 

在上面的代码在该行

 var authContext = new AuthenticationContext(authority); 

返回唯一的例外是

InnerException = {"Couldn't find type for class Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=2.7.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35."} 

我在做什么错了?

+0

http://*.com/questions/20885343/how-to-solve-windows-azure-diagnostic-runtime-error-could-not-create-windowsazu/20910827#20910827。它有帮助吗? – RazvanR

通过使用配置TraceSource“Microsoft.IdentityModel.Clients.ActiveDirectory”写跟踪信息默认ADAL库:https://github.com/AzureAD/azure-activedirectory-library-for-dotnet/blob/51ddc653029a7b3949eb738afbec40dfb30ed6bb/src/ADAL.NET/AdalTrace.cs

更多信息如何配置跟踪见https://github.com/AzureAD/azure-activedirectory-library-for-dotnet/blob/51ddc653029a7b3949eb738afbec40dfb30ed6bb/README.md

我的假设你的web.config有一个跟踪侦听器指向过时的Microsoft.WindowsAzure.Diagnostics。基于Azure .NET SDK的版本安装使用适当的版本 - 最新的一个是2.8.0.0。您还可以使用程序集绑定重定向来强制加载特定版本。

<dependentAssembly> 
    <assemblyIdentity name="Microsoft.WindowsAzure.Diagnostics" publicKeyToken="31bf3856ad364e35" /> 
    <bindingRedirect oldVersion="0.0.0.0-2.8.0.0" newVersion="2.8.0.0" /> 
</dependentAssembly>