Пример #1
0
        private static void CreateFacebookIdentityProvider(string applicationId)
        {
            const string      applicationSecret = "appSecret";
            ManagementService svc = ManagementServiceHelper.CreateManagementServiceClient();

            svc.CreateFacebookIdentityProvider(applicationId, applicationSecret, "email,user_about_me");
            svc.SaveChangesBatch();
        }
Пример #2
0
        /// <summary>
        /// Configures the ACS service namespace with the proper objects for this sample.
        /// </summary>
        /// <remarks>
        /// Existing objects that are needed for this sample will be deleted and recreated.
        /// </remarks>
        static void Main(string[] args)
        {
            const string rpName    = "ASPNET MVC3 Custom Sign-In Page Sample";
            const string rpRealm   = "http://localhost:64000/";
            const string rpReplyTo = "http://localhost:64000/Account/SignIn";

            const string facebookName = "Facebook";
            const string yahooName    = "Yahoo!";

            const string defaultRuleGroupName = "Default rule group for ASPNET MVC3 Custom Sign-In Page Sample";

            // Please update these with your own Facebook application information
            const string applicationId     = "applicationid";
            const string applicationSecret = "applicationsecret";

            string facebookIdpName = String.Format(CultureInfo.InvariantCulture, "Facebook-{0}", applicationId);

            ManagementService svc = ManagementServiceHelper.CreateManagementServiceClient();

            //
            // Clean up pre-existing configuration
            //
            svc.DeleteRelyingPartyByRealmIfExists(rpRealm);
            svc.DeleteRuleGroupByNameIfExists(defaultRuleGroupName);
            svc.DeleteIdentityProviderIfExists(facebookIdpName);
            svc.DeleteIdentityProviderIfExists(yahooName);
            svc.SaveChangesBatch();

            //
            // Create Identity Providers
            //
            IdentityProvider live = svc.GetIdentityProviderByName("uri:WindowsLiveID");;

            IdentityProvider facebook = svc.CreateFacebookIdentityProvider(applicationId, applicationSecret, "email,user_events");

            SetSignInInformation(svc, facebook, facebookName);

            IdentityProvider yahoo = svc.CreateOpenIdIdentityProvider(yahooName, "https://open.login.yahooapis.com/openid/op/auth");

            SetSignInInformation(svc, yahoo, yahooName);

            IdentityProvider[] associatedProviders = new[] { live, facebook, yahoo };

            //
            // Create Relying Party
            //
            RelyingParty relyingParty = svc.CreateRelyingParty(rpName, rpRealm, rpReplyTo, RelyingPartyTokenType.SAML_2_0, false);

            svc.AssociateIdentityProvidersWithRelyingParties(associatedProviders, new[] { relyingParty });

            RuleGroup ruleGroup = svc.CreateRuleGroup(defaultRuleGroupName);

            svc.AssignRuleGroupToRelyingParty(ruleGroup, relyingParty);

            //
            // Create simple rules to pass through all claims from each issuer.
            //
            foreach (IdentityProvider identityProvider in associatedProviders)
            {
                string ruleDescription = string.Format(CultureInfo.InvariantCulture, "Pass through all claims from '{0}'", identityProvider.Issuer.Name);
                svc.CreateRule(identityProvider.Issuer, null, null, null, null, ruleGroup, ruleDescription);
            }
            svc.SaveChangesBatch();

            Console.WriteLine("Sample successfully configured. Press ENTER to continue ...");
            Console.ReadLine();
        }