2012-07-28 51 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