Search code examples
c#.netauthenticationsingle-sign-onclarity

Programmatically login to clarity bypassing sso redirect


I'm having troubles setting up a project that access to my company's clarity application. I've successfully configured a service reference (in my VisualStudio project) to the XOG I'm trying to connect to. My actual code is the following:

        Auth objAuth = new Auth();
        Login login = new Login();
        login.Username = "mylogin";
        login.Password = "mypwd";
        login.TenantId = "clarity";
        MyXOGQueryPortClient client = new MyXOGQueryPortClient();
        string ClaritySessionID = client.Login(login);
        objAuth.SessionID = ClaritySessionID;

Our clarity application have the Company's SSO configured so I've logged in to the SSO service through InternetExplorer and also inside the VisualStudio's Webbrowser. Indeed, if I connect to the clarity URL using a browser I'm NOT redirected to the SSO page. The problem is that when the program calls client.Login() it is returning a ProtocolException "The content type text/html of the response message does not match the content type of the binding (text/html; charset=utf-8)[...]". In the exception I can see the body of the page an it is the SSO redirection page.

The question is: Am I doing something wrong with the code? Can I bypass the SSO page considering that the SSO has already been done? I'm not strictly obliged to use C# (or even .NET) so, if there are solutions based on other languages, any help will be appreciated.

Thank you


Solution

  • I'm not very familiar with Clarity/XOG, but as it appears to be more or less a standard web service, I offer the following possibilities.

    1. Register a user with Clarity that is not part of your SSO implementation, and use that as a kind of service account. It appears that Clarity on Demand offers the capability to mark a user as "external" or not. So registering a user marked as "not" external and using those credentials is probably your easiest way forward. From https://communities.ca.com/thread/241696306

    Have you tried using a xog user with the External Authentication unchecked (on the admin side), and having all the necessary xog rights ?

    1. Barring that, your other option would be to communicate with your SSO login page via standard http protocol by constructing http requests (e.g using HttpClient) and posting appropriate form variables (I'm assuming your SSO doesn't offer a web service) to obtain the authentication cookie. Note the cookie must be valid for the web service site, so depending on exactly how things are setup, you will likely need to programmatically process a chain of http requests to get the correct cookie. Once you have obtained the authentication cookie, pass that cookie along in your web service call.

    For more information on passing cookies with a WCF web service call, see Making web service calls with WCF client + cookies (which uses the OperationContext).

    Or you can consider using a message inspector to apply the cookie(s) to the request.

    See also: