1

我们正在使用 azure key vault 进行 azure 存储 blob 加密。是我为了让它工作而遵循的教程。

我开发了一个示例应用程序和一个用于加密 blob 的包装库。这一切都在示例应用程序中运行良好。但是在实际的软件中,当app请求token的时候,引用了wrapper项目之后就会出现异常,

    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."}

我究竟做错了什么?

4

1 回答 1

2

默认情况下,ADAL 库使用配置的 TraceSource“Microsoft.IdentityModel.Clients.ActiveDirectory”来写入跟踪信息: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> 
于 2016-01-20T01:42:45.027 回答