c# – 使用从STS分配的令牌来调用WCF服务

前端之家收集整理的这篇文章主要介绍了c# – 使用从STS分配的令牌来调用WCF服务前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_502_0@
我一整天都在盯着这一点无济于事,我没有想法. IP-STS处理登录,然后将其传递给RP-STS,RP-STS用声明填充令牌,然后到网站上.这工作正常.我在IP-STS上有一些WCF功能,例如更改密码/重置密码,需要访问它们.阅读后,我应该能够将已经分配的令牌发送到WCF,以确保用户通过身份验证.从我可以看到它发送令牌但不正确,也不是我想要的方式,因为它似乎需要一个用户名.

理想情况下,我希望它获取分配给用户的令牌,而不必重新请求或重新创建任何内容,并且绝对不需要用户名/密码.@H_502_3@

我目前得到的错误是:
从另一方收到了不安全或不正确安全的故障.有关错误代码和详细信息,请参阅内部FaultException.@H_502_3@

详情:
邮件无法处理.这很可能是因为“http://schemas.xmlsoap.org/ws/2005/02/trust/RST/Issue”操作不正确,或者因为邮件包含无效或过期的安全上下文令牌,或者因为存在不匹配绑定之间.如果服务由于不活动而中止了通道,则安全上下文令牌将无效.要防止服务中止空闲会话,请过早增加服务端点绑定的接收超时.@H_502_3@

这是我的网络配置中的相关位.@H_502_3@

客户端web.config@H_502_3@

  1. <system.serviceModel>
  2. <bindings>
  3. <customBinding>
  4. <binding name="UsernameBinding"> <security authenticationMode="UserNameForCertificate" requireSecurityContextCancellation ="false" requireSignatureConfirmation="false" messageProtectionOrder ="SignBeforeEncryptAndEncryptSignature" requirederivedKeys="true">
  5. </security>
  6. <httpTransport/>
  7. </binding>
  8. </customBinding>
  9. <wsFederationHttpBinding>
  10. <binding name="HTTPEndpoint" closeTimeout="00:10:00" openTimeout="00:10:00"
  11. receiveTimeout="00:10:00" sendTimeout="00:10:00" bypassProxyOnLocal="false"
  12. transactionFlow="false" hostNameComparisonMode="StrongWildcard"
  13. maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text"
  14. textEncoding="utf-8" useDefaultWebProxy="true">
  15. <security mode="Message">
  16. <message issuedTokenType="http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV1.1" negotiateServiceCredential="false"> <claimTypeRequirements>
  17.  
  18. <add claimType="http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name" isOptional="false" />
  19. </claimTypeRequirements>
  20.  
  21. <issuer address="http://localhost:13422/MembershipService" bindingConfiguration="UsernameBinding" binding="customBinding">
  22. <identity>
  23. <certificateReference findValue="STSTestCert" x509FindType="FindBySubjectName" storeLocation="CurrentUser" storeName="TrustedPeople" />
  24. </identity>
  25. </issuer>
  26. </message>
  27.  
  28. </security>
  29. </binding>
  30. </wsFederationHttpBinding>
  31. </bindings>
  32.  
  33. <behaviors>
  34. <!-- Credentials configuration -->
  35. <endpointBehaviors>
  36. <behavior name="ServiceBehavior">
  37. <clientCredentials>
  38.  
  39. <clientCertificate findValue="STSTestCert" storeLocation="CurrentUser" storeName="TrustedPeople" x509FindType="FindBySubjectName" />
  40. <serviceCertificate>
  41. <defaultCertificate findValue="STSTestCert" storeLocation="CurrentUser" storeName="TrustedPeople" x509FindType="FindBySubjectName"/>
  42. <authentication certificateValidationMode="PeerOrChainTrust" />
  43. </serviceCertificate>
  44.  
  45. </clientCredentials>
  46. </behavior>
  47. </endpointBehaviors>
  48. </behaviors>
  49.  
  50. <client>
  51. <endpoint address="http://localhost:13422/MembershipService"
  52. binding="wsFederationHttpBinding" bindingConfiguration="HTTPEndpoint"
  53. contract="MembershipService.IAccountMembershipService" name="HTTPEndpoint" behaviorConfiguration="ServiceBehavior">
  54. <identity>
  55. <dns value="localhost"/>
  56. </identity>
  57. </endpoint>
  58. </client>

服务方面:@H_502_3@

  1. <system.serviceModel>
  2.  
  3. <serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true">
  4. <serviceActivations>
  5. <add relativeAddress="IAccountMembershipService.svc" service="AccountMembershipService" factory="System.ServiceModel.Activation.WebServiceHostFactory" />
  6. </serviceActivations>
  7. </serviceHostingEnvironment>
  8.  
  9. <bindings>
  10. <wsHttpBinding>
  11. <binding name="federationBinding" receiveTimeout="00:10:00" sendTimeout="00:10:00" closeTimeout="00:10:00" openTimeout="00:10:00">
  12.  
  13. <security mode="Message">
  14. <message negotiateServiceCredential="true" />
  15. </security>
  16. </binding>
  17.  
  18. </wsHttpBinding>
  19. <wsFederationHttpBinding>
  20. <binding name="federationBinding" closeTimeout="00:10:00" openTimeout="00:10:00"
  21. receiveTimeout="00:10:00" sendTimeout="00:10:00" bypassProxyOnLocal="false"
  22. transactionFlow="false" hostNameComparisonMode="StrongWildcard"
  23. maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text"
  24. textEncoding="utf-8" useDefaultWebProxy="true">
  25.  
  26. <security mode="Message">
  27. <message issuedTokenType="http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV1.1" negotiateServiceCredential="false">
  28. <claimTypeRequirements>
  29.  
  30. <add claimType="http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name" isOptional="false" />
  31. </claimTypeRequirements>
  32.  
  33. <issuer address="http://localhost:13422/MembershipService" bindingConfiguration="UsernameBinding" binding="customBinding">
  34. <identity>
  35. <certificateReference findValue="STSTestCert" x509FindType="FindBySubjectName" storeLocation="CurrentUser" storeName="TrustedPeople" />
  36. </identity>
  37. </issuer>
  38. </message>
  39. </security>
  40. </binding>
  41. </wsFederationHttpBinding>
  42. </bindings>
  43.  
  44.  
  45. <behaviors>
  46. <serviceBehaviors>
  47. <behavior name="serviceBehavior">
  48. <serviceMetadata httpGetEnabled="true" />
  49.  
  50. <serviceCredentials>
  51. <serviceCertificate findValue="CN=STSTestCert" storeLocation="LocalMachine" storeName="My" x509FindType="FindBySubjectDistinguishedName"/>
  52.  
  53. </serviceCredentials>
  54. </behavior>
  55. </serviceBehaviors>
  56. </behaviors>
  57.  
  58. <extensions>
  59. <behaviorExtensions>
  60. <!-- This behavior extension will enable the service host to be Claims aware -->
  61. <add name="federatedServiceHostConfiguration" type="Microsoft.IdentityModel.Configuration.ConfigureServiceHostBehaviorExtensionElement,Microsoft.IdentityModel,Version=0.6.1.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35"/>
  62. </behaviorExtensions>
  63. </extensions>
  64.  
  65. <services>
  66. <service behaviorConfiguration="serviceBehavior" name="STS.IP.Models.AccountMembershipService">
  67. <endpoint binding="wsFederationHttpBinding" bindingConfiguration="federationBinding" name="HTTPEndpoint" contract="STS.IP.Infrastructure.IAccountMembershipService" >
  68. <identity>
  69. <dns value="localhost"/>
  70. </identity>
  71. </endpoint>
  72. <!-- <endpoint binding="wsHttpBinding" bindingConfiguration="" name="HTTPEndpoint" contract="Aurora.WCFIsAlive.IIsAlive" />-->
  73.  
  74. </service>
  75. </services>

对不起,大量的粘贴,但希望有人能发现我的错误
我只是以错误的方式接近它吗?@H_502_3@

解决方法

我不知道这是否有任何帮助,但它可能有点相关…你可以重复使用已发布的令牌,这是我之前做过的事情.我的场景是说ASP.NET站点或WCF服务是WIF安全的,但是ASP.NET站点或WCF服务需要调用另一个需要SAML令牌/ WIF的服务,依此类推如果你可以重用令牌将WIF设置为使用bootstraping.只要第二个Web服务信任相同的STS.

http://msdn.microsoft.com/en-us/library/ee517256.aspx#_bootstrap@H_502_3@

配置设置如下:@H_502_3@

  1. <microsoft.IdentityModel><service><securityTokenHandlers>:

这个值:@H_502_3@

  1. <securityTokenHandlerConfiguration saveBootstrapTokens="true" />

猜你在找的C#相关文章