c# - WCF 用户名身份验证 - 教程中的异常

标签 c# azure acs

我正在从这个页面做教程:http://msdn.microsoft.com/en-us/library/gg185927.aspx 我认为我做的一切都很好,但我遇到了这个异常:

   `An error occurred when processing the security tokens in the message.`

我做错了什么?我使用了样本中的证书。也许我应该创建自己的证书?有什么区别吗?

我注意到硬编码凭据与传入的教程略有不同,因此我在服务标识中更改了它们。在我这样做之前,我遇到了身份验证异常,所以我认为更改它是可以的。

我在任何类型的安全方面都没有经验,但我想最终学习它,所以我希望你们能帮助我:)

编辑: 我不确定这个Realm是否还可以。我通过了 http://localhost:7100/Service/Default.aspx 那里。 我正在本地计算机上运行它,但我不确定这是否是我应该这样做的方式。 编辑2: 这是堆栈跟踪:

Server stack trace: 
at  System.ServiceModel.Channels.SecurityChannelFactory`1.SecurityRequestChannel.ProcessReply(Message reply, SecurityProtocolCorrelationState correlationState, TimeSpan timeout)
at System.ServiceModel.Channels.SecurityChannelFactory`1.SecurityRequestChannel.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]: 
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at WcfService.IStringService.Reverse(String value)
at WcfClient.Program.Main(String[] args) in c:\Users\Hador\Downloads\Windows Azure AD Access Control (ACS) Code Samples\C#\Webservice\Acs2UsernameBindingSample\WcfClient\Program.cs:line 53

我在以下行遇到此错误:

string outputString = stringService.Reverse(userInputString);

最佳答案

看来您的问题在于 token 加密策略及其所需的安全性......

“ token 加密策略

token 加密策略确定 ACS 为依赖方应用程序颁发的 token 是否加密。要要求加密,请选择“需要加密”值。

在 ACS 中,您只能为 SAML 2.0 或 SAML 1.1 token 配置加密策略。 ACS 不支持 SWT 或 JWT token 加密。

ACS 使用包含公钥(.cer 文件)的 X.509 证书对 SAML 2.0 和 SAML 1.1 token 进行加密。然后使用依赖方应用程序拥有的私钥对这些加密的 token 进行解密。有关获取和使用加密证书的详细信息,请参阅证书和 key 。

在 ACS 颁发的 token 上配置加密策略是可选的。但是,当您的依赖方应用程序是通过 WS-Trust 协议(protocol)使用所有权证明 token 的 Web 服务时,必须配置加密策略。如果没有加密 token ,这种特殊场景将无法正常运行。” Taken from here

关于c# - WCF 用户名身份验证 - 教程中的异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21540521/

相关文章:

azure - 将项目上传到 Azure 认知搜索索引时出现 'Request Entity Too Large' 错误 - 如何解决?

c# - 如何在 .NET 中将单个 TextWriter 拆分为多个输出?

azure - 为 Azure AD b2c 添加语言更改按钮

c# - 多态类型和 IXmlSerializable

wpf - 启用侧面加载后,为什么 MSIX 不会在每次应用程序运行时自动检查更新?

azure - 如何为 Azure DevOps 设置 Azure DevOps 代理?

facebook - ACS 和 facebook 登录 -> display=touch 坏了?

c# - 从 Metro 应用程序访问 Azure 中受 ACS 保护的 Web API 站点

c# - WPF PropertyGrid 支持多选

c# - 如何使用 excellibrary.dll 设置 excel 单元格的字体大小