Ejemplo n.º 1
0
        public void Setup()
        {
            var key = "3MVG9A2kN3Bn17hueOTBLV6amupuqyVHycNQ43Q4pIHuDhYcP0gUA0zxwtLPCcnDlOKy0gopxQ4dA6BcNWLab";

            var redirectUrl = new Uri("com.sample.salesforce:/oauth2Callback");             // TODO: Move oauth redirect to constant or config
            var secret      = "5754078534436456018";

            Client = new SalesforceClient(key, secret, redirectUrl);


            var             users = Client.LoadUsers();
            ISalesforceUser user;

            if (users.SingleOrDefault() == null)
            {
                user = new SalesforceUser {
                    Username = "******",
                };
                user.Properties ["instance_url"] = @"https://na15.salesforce.com/";
                user.Properties ["access_token"] = @"00Di0000000bhOg!ARYAQLWetbW6H_Lw78K0SlJ3IU7bBCeOMEhtlP8hTvaWALsYNuxfkikbC5tbAfgdNvxjSkZJ6wHVr8A5qIKM7.KeBmGnoIlg";

                Client.Save(user);
            }
            else
            {
                user = users.FirstOrDefault();
            }

            Client.CurrentUser = user;
        }
Ejemplo n.º 2
0
        public async void Setup()
        {
            var key = "3MVG9A2kN3Bn17hueOTBLV6amupuqyVHycNQ43Q4pIHuDhYcP0gUA0zxwtLPCcnDlOKy0gopxQ4dA6BcNWLab";

            var redirectUrl = new Uri("com.sample.salesforce:/oauth2Callback");
            var secret      = "5754078534436456018";

            Client = new SalesforceClient(key, secret, redirectUrl);

            // Use username/password flow for the demo.
            // This ensures we always have a valid
            // access_token for about 6 hours after this
            // method returns.
            var tokenClient = new HttpClient();
            var formData    = new Dictionary <string, string> {
                { "grant_type", "password" },
                { "client_id", "3MVG9A2kN3Bn17hueOTBLV6amupuqyVHycNQ43Q4pIHuDhYcP0gUA0zxwtLPCcnDlOKy0gopxQ4dA6BcNWLab" },
                { "client_secret", "5754078534436456018" },
                { "username", "*****@*****.**" },
                { "password", "white1@needyrVpFxD3PAvjdH8svH7wLXTN98" },
            };
            var content      = new FormUrlEncodedContent(formData);
            var responseTask = await tokenClient.PostAsync("https://login.salesforce.com/services/oauth2/token", content);

//            responseTask.RunSynchronously(TaskScheduler.Default);
//            responseTask.Wait();
            responseTask.EnsureSuccessStatusCode();
            var responseReadTask = await responseTask.Content.ReadAsStringAsync();

//            var rawResult = await response.Content.ReadAsStringAsync();
//            responseReadTask.RunSynchronously();
//            responseReadTask.Wait();
//            var result = JsonValue.Parse(rawResult);
            var             result = JsonValue.Parse(responseReadTask);
            var             users  = Client.LoadUsers();
            ISalesforceUser user;

            if (users.FirstOrDefault() == null)
            {
                user = new SalesforceUser {
                    Username = "******",
                };
                user.Properties ["instance_url"]              = @"https://na15.salesforce.com";
                user.Properties ["refresh_token"]             = @"5Aep861z80Xevi74eVVu3JCJRUeNrRZAcxky4UcHL1MvM2ALL3Wj_phoRIBXVC2ZcbP_BblUk39RfBF6cwu.lx3";
                user.Properties ["access_token"]              = result["access_token"]; //@"00Di0000000bhOg!ARYAQN2uT2p0I.g1t03eAfogW8ZostVE61ZTMkkrOb1eiWADj9vEABhGUqqO05PQNdUA4pq60a3JTPTwyN6Z7blXpZXJbyHX";
                user.Properties ["requires_reauthentication"] = "false";
                Client.Save(user);
            }
            else
            {
                user = users.FirstOrDefault();
            }

            Client.CurrentUser = user;
        }