Search code examples
winformsazureacs

Access ACS Azure from Winforms


I have an Azure webrole that requires ACSv2 authentication that I want to access from a winforms application. Many of my clients use Windows XP so I can not use the WIF (which is not available on Windows XP). What is the best way to get an authentication token for my web request in this case?


Solution

  • For desktop applications you can do the following:

    1. Get the list of identity providers from your ACS namespace
    2. Display these in a WebBrowser control
    3. After the user logs in, get the token from the WebBrowser control and parse it.

    This is similar to when you want to use ACS in a Windows Phone application. I suggest you take a look at this blog post: Azure ACS on Windows Phone 7. And here is the sample code which parses the token after the user logs in through the WebBrowser control (on WP7):

    private void SignInWebBrowserControl_ScriptNotify(object sender, NotifyEventArgs e) 
    { 
        var acsResponse = ACSResponse.FromJSON(e.Value);
    
        RequestSecurityTokenResponse rstr = null; 
        Exception exception = null; 
        try 
        { 
            string binaryToken = HttpUtility.HtmlDecode(acsResponse.securityToken); 
            string tokenText = RequestSecurityTokenResponseDeserializer.ProcessBinaryToken(binaryToken); 
            DateTime expiration = DateTime.Now + TimeSpan.FromSeconds(acsResponse.expires – acsResponse.created);
    
            rstr = new RequestSecurityTokenResponse 
                        { 
                            Expiration = expiration, 
                            TokenString = tokenText, 
                            TokenType = acsResponse.tokenType 
                        };