wpf - ADFS vNext 客户端身份验证 (WPF) (Windows Server 2016 Preview 3)

标签 wpf powershell authentication oauth adfs

我有一个配置了 ADFS vNext 的 Windows Server 2016 TechnicalPreview 3,作为第一个客户端,我创建了一个 MVC 应用程序作为 ReplingPartyTrust。
ADFS 的身份验证与 MVC 应用程序配合得非常好。
现在问题来了:我编写了一个 native 应用程序 (WPF),我想针对 ADFS 进行身份验证。
我做的步骤是:

  • 为了通知 ADFS 我的新 WPF 客户端,我运行了以下 PowerShell 脚本:

    Add-ADFSClient -ClientType Public -Name “MyClient” -ClientId “E1CF1107-FF90-4228-93BF-26052DD2C714” -RedirectUri “https://E1CF1107-FF90-4228-93BF-26052DD2C714/redir '”
  • 为了验证客户端(Code-Wise),我使用了以下 NuGet 包:
    Microsoft.IdentityModel.Clients.ActiveDirectory (3.5 (Alpha))
    然后我写了以下代码:

  • string authority = "https://win2016preview.server.local/adfs/ls";
    string resourceURI = "https://adfs.server.local/MyMVCApp";
    string clientReturnURI = "https://e1cf1107-ff90-4228-93bf-26052dd2c714/redir";
    string clientID = "E1CF1107-FF90-4228-93BF-26052DD2C714";
    var ac = new AuthenticationContext(authority, false);
    var ar = await ac.AcquireTokenAsync(resourceURI, clientID, new 
    Uri(clientReturnURI), 
    new PlatformParameters(PromptBehavior.Auto, new  
    WindowInteropHelper(this).Handle));
    

    使用此代码,客户端应在 ADFS 进行身份验证(我认为通过 OAuth)并提示用户输入其组织凭据。
    如果我运行该应用程序,则会出现此窗口:

    我选择 Yes (Ja) 并打开凭据提示。同时发生以下异常

    如果服务器 ADFS 在事件日志中出现以下错误消息:

    Microsoft.IdentityServer.Web.Protocols.OAuth.Exceptions.OAuthAuthorizationUnauthorizedClientException: MSIS9321: Received invalid OAuth request. The client 'E1CF1107-FF90-4228-93BF-26052DD2C714' is forbidden to access the resource 'https://adfs.server.local/MyMVCApp. at Microsoft.IdentityServer.Web.Protocols.OAuth.OAuthAuthorization.OAuthAuthorizationRequestContext.ValidateCore() at Microsoft.IdentityServer.Web.Protocols.ProtocolContext.Validate() at Microsoft.IdentityServer.Web.Protocols.OAuth.OAuthAuthorization.OAuthAuthorizationProtocolHandler.GetRequiredPipelineBehaviors(ProtocolContext pContext) at Microsoft.IdentityServer.Web.PassiveProtocolListener.GatherDeviceSecurityToken(ProtocolContext protocolContext, PassiveProtocolHandler protocolHandler) at Microsoft.IdentityServer.Web.PassiveProtocolListener.OnGetContext(WrappedHttpListenerContext context)



    据我所知,ADFS 识别客户端 ID 并尝试对其进行身份验证。但是 ADFS 拒绝了客户端。
    我忘了配置什么吗?客户端应该只提示用户,该用户针对 ADFS 进行身份验证,因此客户端可以拥有 AuthenticationToken。

    我希望你能关注我。先感谢您!

    最佳答案

    解决方案非常简单:)

    添加属性 IssuanceAuthorizationRules (Add-ADFSRelyingPartyTrust )

    -IssuanceAuthorizationRules '=> 问题(类型=“http://schemas.microsoft.com/authorization/claims/permit”值=“真”);'

    关于wpf - ADFS vNext 客户端身份验证 (WPF) (Windows Server 2016 Preview 3),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33327893/

    相关文章:

    .net - 将 AssemblyInfo.cs 中的程序集版本放入 Web.config

    python - 使用python登录网站

    wpf - 在 ComboBox 的 ItemsPanel 上方添加其他控件

    c# - 如何每 1 分钟自动刷新一次 WPF 上的 Datagrid?

    WPF/MVVM : Delegating a domain Model collection to a ViewModel

    regex - Powershell正则表达式,用于两个特殊字符之间的字符串

    c# - 显示内存中的 RGBA 图像

    powershell - PowerShell “$g = $json | ConvertFrom-Json | Group State”结果与 “$g = $json | ConvertFrom-Json ; $g = $g | Group State ;”不同

    node.js - Node/Express JS 认证 : what else other than Passport JS?

    javascript - 使用 Javascript 获取 Windows 身份验证 token 以具有集成安全性(不使用 IIS)