다음을 통해 공유


Windows Azure AppFabric Access Control Service (ACS) v2 – Programmatically Adding Facebook as an Identity Provider Using Management Service

This simple walkthrough shows how to use Management Service of Windows Azure AppFabric Access Control Service (ACS) v2 to programmatically add Facebook as an identity provider. Complete walkthrough can be found here - Windows Azure AppFabric Access Control Service v2 - Adding Identity Provider Using Management Service.

The code related to Facebook is cannibalized from the end-to-end SaaS sample - FabrikamShipping SaaS Demo Source Code.

Code samples with other functionalities is available here - Code Sample: Management Service.

Other ACS code samples available here - Code Samples Index.

Code related to this post can be found here. Next I will call out changes and differences comparing to Windows Azure AppFabric Access Control Service v2 - Adding Identity Provider Using Management Service.

To complete this walkthrough:

  1. Obtain Facebook application id and application secret. Instructions on how to do so can be found here - How To: Configure Facebook as an Identity Provider. Skip to Step 3 – Obtaining a Facebook Application ID and a Facebook Application Secret.

  2. Identity provider key is based on Facebook’s application id and application secret obtained in previous step. There is related code change:

     var facebookKeys = new[]
        {
            new IdentityProviderKey
                {
                    IdentityProvider = facebook,
                    StartDate = DateTime.UtcNow,
                    EndDate = DateTime.UtcNow.AddYears(1),
                    Type = "ApplicationKey",
                    Usage = "ApplicationId",
                    Value = Encoding.Default.GetBytes(facebookAppId)
                },
            new IdentityProviderKey
                {
                    IdentityProvider = facebook,
                    StartDate = DateTime.UtcNow,
                    EndDate = DateTime.UtcNow.AddYears(1),
                    Type = "ApplicationKey",
                    Usage = "ApplicationSecret",
                    Value = Encoding.Default.GetBytes(facebookAppSecret)
                }
        };
    
  3. Test your work by running the code and then logging in to Access Control Service Management Portal at https://portal.appfabriclabs.com/. Navigate to Identity Providers page and verify Facebook is added as identity provider.

ACSManagementService - Facebook.zip