3

我正在用 c# 创建一个 Windows 8 客户端应用程序。这个应用程序将使用 SAP 的 odata 服务。对于身份验证,我需要 ADFS 颁发的 SAML 令牌。有什么方法可以使用 Windows 凭据从 ADFS 获取 SAML 令牌?

4

1 回答 1

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;
}
于 2012-11-16T12:56:57.553 回答