ADFS from a .Net SDK application

Overview 

In a previous post I examined how to configure RM to authenticate via ADFS when using the native client, in this post I show how to write a .Net SDK application to authenticate via ADFS.

The code

This is the console application I used in the video above

class Program
{

    private static ClientAuthenticationMechanism getAuthenticationMechanism(string dbId)
    {
        foreach (int authenticationMethod in new int[] { 3, 2, 0 })
        {
            if (Database.IsAuthenticationMethodSupported("G1", (ClientAuthenticationMechanism)authenticationMethod))
            {
                return (ClientAuthenticationMechanism)authenticationMethod;
            }
        }

        throw new ApplicationException("No Authentication method found.");
    }


    static void Main(string[] args)
    {
        TrimApplication.TrimBinariesLoadPath = "D:\\82\\x64\\Debug";
        TrimApplication.HasUserInterface = true;
        TrimApplication.Initialize();

        using (Database database = new Database())
        {
            database.Id = "G1";
            database.WorkgroupServerName = "local";
            database.AuthenticationMethod = getAuthenticationMechanism("G1");

            database.Connect();


            Console.WriteLine("{0} - {1}", database.CurrentUser.FullFormattedName, database.CurrentUser.Uri);
        }
    }
}

Warning

As I mention in the video the method Database.IsAuthenticationMethodSupported will only return a valid response if the native client has connected previously from the current machine.  If no connection has been made previously then all authentication mechanisms will return true.

Written on November 3, 2015