c# - 最新的 ADAL 无法生成不记名 token

标签 c# azure token azure-active-directory adal

我正在尝试使用以下代码使用最新版本的 ADAL 包 (3.13.9) 生成 authcontext,但出现异常。但是,我将 ADAL 版本降级到 v2.22.302111727,它可以正常工作。我使用的是 Visual Studio 2017。3.13.9 有什么问题吗?

authContext = new AuthenticationContext(authority, true);

System.TypeInitializationException occurred HResult=0x80131534
Message=The type initializer for 'Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext' threw an exception.
Source=Microsoft.IdentityModel.Clients.ActiveDirectory StackTrace:
at Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext..ctor(String authority, Boolean validateAuthority) at DestinationProvider.AADToken.d__4.MoveNext() in D:\Repo\MyProjects\nv\nv\DestinationProvider\AADToken.cs:line 32 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() at ReplLoop.ReplLoop.d__1.MoveNext() in D:\Repo\MyProjects\nv\nv\nvReplLoop\ReplLoop.cs:line 52

Inner Exception 1: TypeInitializationException: The type initializer for 'Microsoft.IdentityModel.Clients.ActiveDirectory.PlatformPlugin' threw an exception.

Inner Exception 2: AdalException: Assembly required for the platform not found. Make sure assembly 'Microsoft.IdentityModel.Clients.ActiveDirectory.Platform, Version=3.13.8.999, Culture=neutral, PublicKeyToken=31bf3856ad364e35' exists

Inner Exception 3: FileNotFoundException: Could not load file or assembly 'Microsoft.IdentityModel.Clients.ActiveDirectory.Platform, Version=3.13.8.999, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.

最佳答案

听起来您可能遇到了这个问题:

https://github.com/AzureAD/azure-activedirectory-library-for-dotnet/issues/511

我正在使用isabekyan's workaround ,因为这已经解决了我的问题。

他们建议在使用authenticationContext之前添加对以下代码的调用

  private static void SomeMethodToLinkPlatform()
    {
        var creds = new UserPasswordCredential("testUser", "SomePassword");
    }

关于c# - 最新的 ADAL 无法生成不记名 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43289542/

相关文章:

azure - 如何在AKS集群中创建Windows节点池?

sql-server - 如何将 SQL Server Profiler 与具有 AAD 集成安全性的 Azure SQL Server 结合使用,其中 AAD 用户与登录的桌面帐户不同?

php - Symfony2 唯一 token 生成器

c# - MVVM 模式查询

c# - Enum.ToString() 在工具提示中不起作用

python - 避免对通过 Python SDK 发送到事件中心的数据进行 Base64 编码

c# - Microsoft Graph - 无法以静默方式获取 token

token - 聊天GPT : How to use long texts of unknown content in a prompt?

c# - 了解 BackgroundWorker

c# - 将 .NET 结构与 WINAPI 函数结合使用