WIF WSTrustSerializationException - Диалект утверждений не может быть установлен в пользовательское значение? - PullRequest
2 голосов
/ 20 января 2011

У меня следующий код, пытающийся сделать запрос «Issue» с WIF.

Когда я его запускаю, я получаю следующее исключение.Разве нельзя запросить токен безопасности, используя проблему с пользовательской заявкой?

Additional information: ID3257: RequestSecurityToken contains at least one Claim with a Claim value specified but the RequestClaimCollection.Dialect is set to 'urn:custom_namespace:sts:1_0'. The RequestClaimCollection.Dialect must be set to 'http://docs.oasis-open.org/wsfed/authorization/200706/authclaims' for the value to be serialized out.

Код:

private const string CLAIMS_DIALECT = "urn:custom_namespace:sts:1_0";
private const string REQUEST_CLAIM_TYPE = "urn:custom_namespace:sts:1_0";
private const string REQUEST_CLAIM_VALUE = "urn:oasis:names:tc:SAML2.0:consent:current-explicit";


public System.IdentityModel.Tokens.SecurityToken RequestSecurityToken(string input)
{
    System.Net.ServicePointManager.ServerCertificateValidationCallback = ((sender, certificate, chain, sslPolicyErrors) => true);

    WS2007HttpBinding binding = new WS2007HttpBinding();
    binding.Security.Mode = SecurityMode.TransportWithMessageCredential;
    binding.Security.Message.ClientCredentialType = MessageCredentialType.Certificate;

    var trustChannelFactory = new WSTrustChannelFactory(binding, new EndpointAddress(new Uri(STS_URL)));
    trustChannelFactory.TrustVersion = TrustVersion.WSTrust13;

    trustChannelFactory.Credentials.ClientCertificate.Certificate = GetCertificateBySubjectName(LOCALHOST_CERTIFICATE_SUBJECT_NAME);
    trustChannelFactory.Credentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.PeerOrChainTrust;
    trustChannelFactory.Credentials.ServiceCertificate.Authentication.RevocationMode = X509RevocationMode.NoCheck;

    try
    {
        RequestSecurityToken rst = new RequestSecurityToken();

        rst.AppliesTo = new EndpointAddress(new Uri(APPLIES_TO_URL), new X509CertificateEndpointIdentity(GetCertificateBySubjectName(LOGON_SERVICE_CERTIFICATE_SUBJECT_NAME)));
        rst.ActAs = BuildSecurityTokenElementFromInput(input);
        rst.RequestType = RequestTypes.Issue;
        rst.Lifetime = new Lifetime(DateTime.UtcNow, DateTime.UtcNow.AddMinutes(5));
        rst.Claims.Dialect = CLAIMS_DIALECT;
        var requestClaim = new RequestClaim(REQUEST_CLAIM_TYPE, false, REQUEST_CLAIM_VALUE);
        rst.Claims.Add(requestClaim);

        WSTrustChannel channel = (WSTrustChannel)trustChannelFactory.CreateChannel();

        RequestSecurityTokenResponse rstr = null;

        return channel.Issue(rst, out rstr);
    }
    finally
    {
        trustChannelFactory.Close();
    }
}

Ответы [ 2 ]

0 голосов
/ 01 августа 2014

Вы хотите добавить требуемые претензии в RequestSecurityToken.Это означает, что STS должен выдать токен с указанными претензиями.В принципе, в этом нет необходимости, но если вы уверены, вы должны установить диалект.Это правда.

0 голосов
/ 28 апреля 2011

Я не уверен, что вам нужно изменить rst.Claims.Dialect, чтобы сделать эту работу. Что произойдет, если вы оставите его по умолчанию?

...