2012-07-28 115 views
0

我已经能够为集成项目创建一个很好的WCF服务,它可以返回纯XML,JSON和SOAP结果。在我开始实施安全性之前,这种方法非常有效。在WCF服务内置的WS安全功能,使用它与正常工作WebHttpBindings时绕过:WCF Rest服务和身份验证方案

<webHttp defaultOutgoingResponseFormat="Json"/> 

[OperationContract()] 
[WebGet(UriTemplate = "GetSomething/{someID}/{anotherID}?somethingElse={somethingElse}")] 
SomeResponse GetSomething(string someID,string anotherID, DateTime somethingElse) 

我很喜欢我的第一个宁静的API,但可惜打我需要完成一个项目并且要求包括安全的身份验证策略。我不需要将结果作为json返回,也不一定是休息服务,但这引起了我的好奇心。

...任何关于认证策略/ WCF REST服务的好主意?

回答

0

您可能要clientCredentialType = “证书” 或 “窗口”

<webHttpBinding> 
    <binding name ="RestSSL"> 
    <security mode ="Transport"> 
     <transport clientCredentialType= "Windows" /> 
    </security> 
    </binding>     
</webHttpBinding> 

如果使用证书,你还需要设置serviceBehavior的certificateValidationMode喜欢的东西PeerTrust,ChainTrust等http://msdn.microsoft.com/en-us/library/system.servicemodel.security.x509certificatevalidationmode.aspx

<behaviors> 
    <serviceBehaviors> 
    <behavior> 
     <dataContractSerializer maxItemsInObjectGraph="1048576"/> 
     <serviceMetadata httpGetEnabled="False" httpsGetEnabled="True"/> 
     <serviceDebug includeExceptionDetailInFaults="False"/> 
     <serviceCredentials> 
     <!-- Please note: the app pool will need an identity with access to this cert--> 
     <serviceCertificate findValue="myCertSubject.myDomain.com" 
          storeLocation="LocalMachine" 
          storeName="My" 
          x509FindType="FindBySubjectName"/> 
     <clientCertificate> 
      <authentication certificateValidationMode="PeerTrust"/> 
     </clientCertificate> 
     </serviceCredentials> 
    </behavior> 
    </serviceBehaviors> 
0

一般来说,大多数人倾向于在确保安静的wcf服务时使用OAuth。 OAuth是一种开放式协议,可通过桌面和Web应用程序以简单标准的方法实现安全的API身份验证。它允许客户端提供一个消费者密钥,用于标识每次服务呼叫时必须发送的客户端。该信息作为HTTP授权标头的一部分发送。从here

下载的OAuth类实现细节,看看这个Code Project Article

+0

我已经在过去实施的OpenID的SSO。如果OAuth lib很简单,那么这可能是票 – 2012-07-28 07:35:40

+0

我不明白,你是什么意思的“检查票” – Anand 2012-07-28 12:32:49