Taking Control over Azure Access Control Service HRD (without the Help from jQuery)

Vittorio wrote a post earlier today showing how to fetch the identity provider feed from ACS and use it to drive the sign-in handshake from within your application and UI.

This is indeed a very useful (and user friendly) approach. Call me old fashioned, but I’d rather like to do that using C#/server side ;)

I wrote a simple class that turns the ACS identity provider feed into an object model. In essence the logic looks like this:

public async Task<List<IdentityProviderInformation>> GetAsync(
 
string
protocol)

{

    var url = string.Format(

        https://{0}.{1}/v2/metadata/IdentityProviders.js?protocol={2}&realm={3}&context={4}&version=1.0”,

        AcsNamespace,

        “accesscontrol.windows.net”,

        protocol,

        Realm,

        Context);

 

    var jsonFormatter = new JsonMediaTypeFormatter();

    jsonFormatter.SupportedMediaTypes.Add(
     
new MediaTypeHeaderValue(“text/javascript”));

 

    var formatters = new List<MediaTypeFormatter>()

    {

        jsonFormatter

    };

 

    var client = new HttpClient();

    var response = await client.GetAsync(new Uri(url));

 

    return await
      response.Content.ReadAsAsync<
List<IdentityProviderInformation
>>(
        formatters);

}

 

From there you can data bind to a UI control (e.g. WPF, WP, WebForms) or pass on to a MVC view (honoring the MVC model ;)).

Here’s the full source code, and here a WPF client sample.

HTH

This entry was posted in Azure, IdentityModel. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s