3

At the moment i'm working on a project where my application has to validate with ADFS to login.

I found some code to get the token from ADFS but it keeps giving me the error above without any good description about the error.

This is the code I use:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ServiceModel;
using System.ServiceModel.Security;
using System.Net;
using System.IdentityModel.Protocols.WSTrust;
using System.IdentityModel.Tokens;

namespace ADFS_token_test_3
{
    class Program
    {
    static void Main(string[] args)
    {
        go();
    }

    static public EndpointAddress ep;
    static public WSTrustChannelFactory factory;

    public static string go()
    {
        WS2007HttpBinding binding = new WS2007HttpBinding(SecurityMode.TransportWithMessageCredential);
        binding.Security.Message.EstablishSecurityContext = false;
        binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;

        binding.Security.Message.ClientCredentialType = MessageCredentialType.UserName;
        ep = new EndpointAddress("https://companyname.nl/adfs/services/trust/13/usernamemixed");

        factory = new WSTrustChannelFactory(binding, ep);
        factory.TrustVersion = TrustVersion.WSTrust13;

        factory.Credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;
        factory.Credentials.UserName.UserName = "username";
        factory.Credentials.UserName.Password = "password";

        var rst = new RequestSecurityToken
        {
            RequestType = RequestTypes.Issue,
            AppliesTo = new EndpointReference("https://companyname.nl/adfs/services/trust/13/usernamemixedr"),
            KeyType = KeyTypes.Bearer,
        };

        IWSTrustChannelContract channel = factory.CreateChannel();
        // Error line 
        GenericXmlSecurityToken genericToken = channel.Issue(rst)
         as GenericXmlSecurityToken;

        return genericToken.TokenXml.InnerXml.ToString();
    }
  }
}

Error occurs on the line with the error comment.

Anybody has a clue?

Noise
  • 41
  • 1
  • 3

1 Answers1

0

Check that your CRL Distribution Point can be reached.

I have encountered that problem in some of the ADFS Single SignOn web applications. ADFS uses PKI Certificates (e.g. for signing the tokens). These certificates often have a CRL (Certificate Revocation List) that must be reachable. If the revocation list cannot be checked, you tend to have the above error message. For me it was a firewall standing in between my application and the CDP (CRL Distribution Point) server.

PS. You can verify the CDP when looking at the details of the certificate itself.