Exemple #1
0
        internal bool UpdateB2C(Dictionary <string, string> updates, string userId)
        {
            if (String.IsNullOrEmpty(userId))
            {
                return(false);
            }
            AADUser        aad    = new AADUser(tenant, id, secret);
            B2CGraphClient b2c    = new B2CGraphClient(id, secret, tenant);
            string         result = b2c.UpdateUser(userId, JsonConvert.SerializeObject(updates)).Result;

            if (!result.Contains("Error"))
            {
                return(true);
            }
            return(false);
        }
        public async Task <HttpResponseMessage> Post()
        {
            // The post body should contain a JSON representation of the AADUser object
            HttpResponseMessage response = new HttpResponseMessage();
            string  content = Request.Content.ReadAsStringAsync().Result;
            AADUser model   = null;

            try
            {
                // Convert the JSON payload to an AADUser
                model = JsonConvert.DeserializeObject <AADUser>(content);
            }
            catch (Exception ex)
            {
                response.StatusCode = HttpStatusCode.InternalServerError;
                response.Content    = new StringContent(ex.Message);
            }

            if (model != null)
            {
                // Authenticate to the Microsoft Graph and create a graph client
                string           clientId         = ConfigurationManager.AppSettings["ClientId"];
                string           clientSecret     = ConfigurationManager.AppSettings["ClientSecret"];
                string           tenant           = ConfigurationManager.AppSettings["Tenant"];
                ClientCredential clientCredential = new ClientCredential(clientSecret);
                IConfidentialClientApplication clientApplication = ClientCredentialProvider.CreateClientApplication(clientId, clientCredential, null, tenant);
                ClientCredentialProvider       authProvider      = new ClientCredentialProvider(clientApplication);
                GraphServiceClient             graphClient       = new GraphServiceClient(authProvider);

                var user = new User
                {
                    AccountEnabled    = true,
                    DisplayName       = model.DisplayName,
                    MailNickname      = model.MailNickname,
                    UserPrincipalName = model.UserPrincipalName,
                    PasswordProfile   = new PasswordProfile
                    {
                        ForceChangePasswordNextSignIn = false,
                        Password = model.Password
                    }
                };

                try
                {
                    // Add the user to Azure AD
                    User newUser = await graphClient.Users
                                   .Request()
                                   .AddAsync(user);

                    // Capture the object ID of the newly created user
                    model.Id            = newUser.Id;
                    response.StatusCode = HttpStatusCode.OK;
                    response.Content    = new StringContent(JsonConvert.SerializeObject(model), Encoding.UTF8, "application/json");
                }
                catch (Exception ex)
                {
                    response.StatusCode = HttpStatusCode.InternalServerError;
                    response.Content    = new StringContent(ex.Message);
                }
            }

            return(response);
        }
Exemple #3
0
        protected void signUpBtn_Click(object sender, EventArgs e)
        {
            Page.Validate("registration");
            if (!Page.IsValid)
            {
                return;
            }
            //if trade user, then accountEnabled is true automatically without approval
            GraphApi.B2CNewUser newUser = new B2CNewUser
            {
                accountEnabled = (distributeChk.Checked) ? false : true,
                signInNames    = new SignInName[] { new SignInName
                                                    {
                                                        type  = "emailAddress",
                                                        value = emailTxt.Text
                                                    } },
                displayName     = firstNameTxt.Text + " " + lastNameTxt.Text,
                creationType    = "LocalAccount",
                givenName       = firstNameTxt.Text,
                mailNickname    = emailTxt.Text.Split('@')[0],
                passwordProfile = new PasswordProfile
                {
                    password = passTxt.Text,
                    forceChangePasswordNextLogin = false
                },
                passwordPolicies = "DisablePasswordExpiration",
                streetAddress    = emailTxt.Text,
                surname          = lastNameTxt.Text,
                usageLocation    = "US",
                userType         = "member",
                extension_a67c327875c34024bd4523a3d66619ba_Birthdate            = birthdayTxt.Text,
                extension_a67c327875c34024bd4523a3d66619ba_Email                = emailTxt.Text,
                extension_a67c327875c34024bd4523a3d66619ba_Employer             = (employerDDL.SelectedIndex > 0) ? employerDDL.SelectedItem.Value : null,
                extension_a67c327875c34024bd4523a3d66619ba_SuccessFactorsRoleID = (!distributeChk.Checked) ? "Trade_ID" : "Dist_ID",
                extension_a67c327875c34024bd4523a3d66619ba_SuccessFactorsID     = (Guid.NewGuid()).ToString().Replace("-", "").Substring(0, 20) + "_EXT",
                country = (countryDDL.SelectedIndex > 0) ? countryDDL.SelectedItem.Value : null,
                state   = (stateDDL.SelectedIndex > 0) ? stateDDL.SelectedItem.Value : null
            };
            if (distributeChk.Checked)
            {
                newUser.extension_a67c327875c34024bd4523a3d66619ba_Region             = GetRegion();
                newUser.extension_a67c327875c34024bd4523a3d66619ba_BeamSuntorySponsor = beamSuntorySponsorTxt.Text;
                newUser.extension_a67c327875c34024bd4523a3d66619ba_Area             = (areaDDL.SelectedIndex > 0) ? areaDDL.SelectedItem.Value : null;
                newUser.extension_a67c327875c34024bd4523a3d66619ba_OnOffPremise     = (onOffPremiseDDL.SelectedIndex > 0) ? onOffPremiseDDL.SelectedItem.Value : null;
                newUser.extension_a67c327875c34024bd4523a3d66619ba_CommercialRegion = GetCommercialRegion();
                newUser.extension_a67c327875c34024bd4523a3d66619ba_Division         = (stateDDL.SelectedIndex > 0 && countryDDL.SelectedItem.Value == "United States") ? GetDivision(stateDDL.SelectedItem.Value) : null;
            }
            GraphApi.AADUser aad  = new AADUser(tenant, id, secret);
            GraphApi.B2CUser user = null;
            try
            {
                user = aad.CreateUser(newUser);
            }
            catch (Exception ex)
            {
                //signupFormPnl.ContentTemplateContainer.Controls.Add(new LiteralControl("<div>" + ex.Message + "</div><div>" + ex.StackTrace + "</div><div>" + ex.InnerException + "</div>"));
                //signupFormPnl.Update();

                successMsg.Controls.Add(new LiteralControl("<h1>Whoops!</h1><p>We were unable to complete your registration at this time. If you are still experiencing issues, please contact <a href='mailto:[email protected]'>[email protected]</a> for assistance.</p><a class='btn' href='/'>OK</a>" + ex.Message));
                successMsg.Controls.Add(new LiteralControl("<style>.form .row {display:none !important;}.footer .btn {display:none;}</style>"));
                successMsg.Controls.Add(new LiteralControl("<div class='error' style='display:none'><div>New User Details:</div><div>" + Newtonsoft.Json.JsonConvert.SerializeObject(user) + "</div></div>"));
                signupFormPnl.Update();
            }
#if DEBUG
            successMsg.Controls.Add(new LiteralControl("<div style='display:none'><div>New User Details:</div><div>" + Newtonsoft.Json.JsonConvert.SerializeObject(user) + "</div></div>"));
#endif
            if (user != null)
            {
                if (user.userType != "Error")
                {
                    //woo... also indicate to the user that they have been signed up pending approval
                    //send pending user email to admin
                    if (distributeChk.Checked)
                    {
                        successMsg.Controls.Add(new LiteralControl("<h1>Registration Complete!</h1><p>You have successfully registered for Beam Suntory Connect. Your registration is pending approval which can take 1 - 2 business days.</p><a class='btn' href='/'>OK</a>"));
                    }
                    else
                    {
                        successMsg.Controls.Add(new LiteralControl("<h1>Registration Complete!</h1><p>You have successfully registered for Beam Suntory Connect and can use the system immediately. Note that youre learning courses will take 1 -2 business days to be available.</p><a class='btn' href='/'>Login</a>"));
                    }
                    bool TradeUser = (distributeChk.Checked) ? false : true;
                    Classes.Helpers.LogUserChange(TradeUser, false, GetUserDictionary(user));
                    successMsg.Controls.Add(new LiteralControl("<style>.form .row {display:none !important;}.footer .btn {display:none;}</style>"));
                    signupFormPnl.Update();
                }
                else
                {
#if PROD
                    string resetUrl = "https://passwordreset.microsoftonline.com/?ru=https%3a%2f%2flogin.microsoftonline.com%2fextbeamsuntory.onmicrosoft.com%2freprocess%3fctx%3drQIIAbVSv4vTcBQnSTt4HCgFQTiQG24S0uSbpL220KG9_rCl_YZrm4vNlqTftN80ybfXfEua4OCqooOIQic5t9vURW_wD7jFcxNHJ3F0ctNWwUXQyeF9eLz3Ph_e4_NucCALSnuWJZkSkk3ezqF9XnFEky8UkMivAzgj2bGBo8wzW1e2P78RMzuN6tPlzt3vW6_erZjraEktZPrhIqBkHmdJ4GN7TkLi0KxN_FOmP6F0FpYEwSNjHGR_d0ng4QBtZgSKhL-rCMRc0IkkbHCOwtlrhrlgmDssc49NAVGWV2waBbzWf8Yyp-w1o9uDN_UjywirpD5LLOdAV6ZRufyRvaxWNjobIHOcoE9_VL6w6Z97fmXTxws0jx9xV8kMBXhkkyBANs3iESVTFKy4-wyK24O-dohV3FY6Okg6OoxMXaS2381DSYuhD13D1-jQNTA8EEVDryedwThnDLoUNrVo6E4ltdmYGrqWtHCEj-peveUSrDYPl119KA2TCoUunKhrLqyN_DU3hrUhhX7bg66tDJMqNtzKshWIL7l_-HDG7YkyyOWkEeJFVCzwShEB3txfZw6QRUsumnkpv3_ObSPfxN7ur6M_cMxFivmWYk7Sa_Prj58_fPvgdu3Fe547eZLJnqeFTk-YjYuJE_eaqpsb3QLuMozCQQGAmNZacmV23OsaSWOAvaislMDZpf_xDT8A0&mkt=en-US&hosted=0&device_platform=Windows+10&nca=1&domain_hint=extbeamsuntory.onmicrosoft.com";
#endif
#if DEV
                    string resetUrl = "https://passwordreset.microsoftonline.com/?ru=https%3a%2f%2flogin.microsoftonline.com%2fbsib2cdev.onmicrosoft.com%2freprocess%3fctx%3drQIIAa1SO2zTUBSV7UQChARCQiJMIHUCOX7v2Wk-UoZ8HOQS28JxEmyxOPZz8kzslyavpPHExAALqjplKowdEUKoYmXJ1BExMIBYEBNiYKQBiaVi63DPcO_R0T3n3lsCzMPKxmCAPIRlT_QLuCgqIfDEUgkD8aRgGMihD0NleuXC5S83V_u5Tnr3xdf39PX3vU9LLlfvaHXUaOJHeZrExJ_SGQ1Z3qfxIWeMGJvMKpI0pkOS5P9NaTImCV5zJIalwYwMkB-cFpCot8NGSFrjFM8mbznumOMe89xTPgOBLC_5LE7EbueA5w75a2V6W5F7buB4eq_kFSwE5sloWK1-5C-ZtbXOGuiUpPjzqc43PvtnxR98dnsHTxd7wlU6wQkJfJok2Gd5EjD6ECdL4RmHF1t2p3uPmGRLafdh2u4bc68PmB_rm06kAzfWFCetMdPuym4HACeyxm17RAykMh1p0G12gWu7sRu1iEbmpKeOVS2ixIk15EStyG06zLB9oDcAMGxr1LaHyOyrzEEqMJp6wUhVxWx2FS0Br4Tcf8M7Eja8YmEAoQJE4CNZVHw5EEtyaVMMoOwPQhmgchGthIs49sj4xl-_HwTuOMP9ynAvsyfXfvLz3O6DaF8_eH79Xd1tvFllpbYlTYblNFxYd8yoENyH0e5sPrNLEC5YU5Nrk21Ld9OWTcbzarECj86f8Q_8Bg2&mkt=en-US&hosted=0&device_platform=Windows+10&nca=1&domain_hint=BSIB2CDev.onmicrosoft.com";
#endif
                    successMsg.Controls.Add(new LiteralControl("<h1>Whoops!</h1><p>We were unable to complete your registration because your account already exists. Click the buttons below to either log in or to reset your password. If you are still experiencing issues, please contact <a href='mailto:[email protected]'>[email protected]</a> for assistance.</p><a class='btn' href='/'>Login</a> <a class='btn' href='" + resetUrl + "'>Reset Password</a>"));
                    successMsg.Controls.Add(new LiteralControl("<style>.form .row {display:none !important;}.footer .btn {display:none;}</style>"));
                    successMsg.Controls.Add(new LiteralControl("<div class='error' style='display:none'><div>New User Details:</div><div>" + Newtonsoft.Json.JsonConvert.SerializeObject(user) + "</div></div>"));
                    signupFormPnl.Update();
                }
            }
        }