2012-10-16 43 views
3

我正在c#中創建一個Windows 8客戶端應用程序。此應用程序將使用SAP的odata服務。對於身份驗證,我需要由ADFS發佈的SAML令牌。是否有任何方法使用Windows憑據從ADFS獲取SAML令牌?使用Windows憑據從ADFS獲取SAML令牌

回答

0

您可以使用下面的代碼獲取SAML令牌。

var factory = new WSTrustChannelFactory(new Microsoft.IdentityModel.Protocols.WSTrust.Bindings.UserNameWSTrustBinding(SecurityMode.TransportWithMessageCredential), adfsEndpoint); 

factory.Credentials.UserName.UserName = "username"; 
factory.Credentials.UserName.Password = "********"; 
factory.Credentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None; 
factory.TrustVersion = TrustVersion.WSTrust13; 
WSTrustChannel channel = null; 
try 
{ 
    var rst = new RequestSecurityToken 
    { 
     RequestType = WSTrust13Constants.RequestTypes.Issue, 
     AppliesTo = new EndpointAddress("https://yourserviceendpoint.com/"), 
     KeyType = KeyTypes.Bearer, 
    }; 
    channel = (WSTrustChannel)factory.CreateChannel(); 
    return channel.Issue(rst); 
} 
catch (Exception e) 
{ 
    return null; 
} 
+0

是否有理由忽略異常? –

+0

WSTrustChannelFactory在地鐵應用程序中不可用。 – user1734463