public void RequestAccessToken_InvalidClientSecret_InvalidClientSecret() { var target = new UsernamePasswordAuthenticationFlow(TestConfig.ClientId, "invalid client secret", TestConfig.Username, TestConfig.Password); target.TokenRequestEndpointUrl = TestConfig.TokenRequestEndpointUrl; ExceptionAssert.IsThrowing(new SalesforceException(SalesforceError.InvalidClient, "invalid client credentials"), () => { target.Authenticate(); }); }
public void RequestAccessToken_InvalidPassword_InvalidPassword() { var target = new UsernamePasswordAuthenticationFlow(TestConfig.ClientId, TestConfig.ClientSecret, TestConfig.Username, "invalid password"); target.TokenRequestEndpointUrl = TestConfig.TokenRequestEndpointUrl; ExceptionAssert.IsThrowing(new SalesforceException(SalesforceError.InvalidPassword, "authentication failure - invalid password"), () => { target.Authenticate(); }); }
public void Authenticate_InvalidUsername_AuthenticationFailure() { var target = new UsernamePasswordAuthenticationFlow(TestConfig.ClientId, TestConfig.ClientSecret, "invalid user name", TestConfig.Password); target.TokenRequestEndpointUrl = TestConfig.TokenRequestEndpointUrl; ExceptionAssert.IsThrowing(new SalesforceException(SalesforceError.AuthenticationFailure, "authentication failure"), () => { target.Authenticate(); }); }
public void RequestAccessToken_ValidCredentials_Authenticated() { var target = new UsernamePasswordAuthenticationFlow(TestConfig.ClientId, TestConfig.ClientSecret, TestConfig.Username, TestConfig.Password); target.TokenRequestEndpointUrl = TestConfig.TokenRequestEndpointUrl; var actual = target.Authenticate(); Assert.IsNotNull(actual); Assert.IsTrue(actual.AccessToken.Length > 0); Assert.IsTrue(actual.InstanceUrl.Length > 0); Assert.IsTrue(Uri.IsWellFormedUriString(actual.InstanceUrl, UriKind.Absolute)); }
public void Authenticate_Success_AuthenticationInfo() { var response = MockRepository.GenerateMock<IRestResponse>(); response.Expect(r => r.Content).Return("{ access_token: 'access token 1', instance_url: 'instance url 2' }"); response.Expect(r => r.StatusCode).Return(HttpStatusCode.OK); var restClient = MockRepository.GenerateMock<IRestClient>(); restClient.Expect(r => r.BaseUrl).SetPropertyWithArgument(new Uri("https://login.salesforce.com/services/oauth2/token")); restClient.Expect(r => r.Execute(null)).IgnoreArguments().Return(response); var target = new UsernamePasswordAuthenticationFlow(restClient, "clientId", "clientSecret", "userName", "password"); var actual = target.Authenticate(); Assert.AreEqual("access token 1", actual.AccessToken); Assert.AreEqual("instance url 2", actual.InstanceUrl); }
public void Publish_Package_InstalledAndRunning() { var clientId = ConfigHelper.ReadAppSetting ("SalesforceSharp.FunctionalTests", "ClientId"); var clientSecret = ConfigHelper.ReadAppSetting ("SalesforceSharp.FunctionalTests", "ClientSecret"); var username = ConfigHelper.ReadAppSetting ("SalesforceSharp.FunctionalTests", "Username"); var password = ConfigHelper.ReadAppSetting ("SalesforceSharp.FunctionalTests", "Password"); var flow = new UsernamePasswordAuthenticationFlow (clientId, clientSecret, username, password); var client = new SalesforceClient(); client.Authenticate (flow); var users = client.Query<UserStub> ("SELECT Username, Email FROM USER"); Assert.That (users.Count > 0); Assert.IsFalse (String.IsNullOrEmpty (users [0].Username)); Assert.IsFalse (String.IsNullOrEmpty (users [0].Email)); Assert.IsTrue (String.IsNullOrEmpty (users [0].Alias)); }
public void Authenticate_Failed_Exception() { var response = MockRepository.GenerateMock<IRestResponse>(); response.Expect(r => r.Content).Return("{ error: 'authentication failure', error_description: 'authentication failed' }"); response.Expect(r => r.StatusCode).Return(HttpStatusCode.BadRequest); var restClient = MockRepository.GenerateMock<IRestClient>(); restClient.Expect(r => r.BaseUrl).SetPropertyWithArgument(new Uri("http://tokenUrl")); restClient.Expect(r => r.Execute(null)).IgnoreArguments().Return(response); var target = new UsernamePasswordAuthenticationFlow(restClient, "clientId", "clientSecret", "userName", "password"); target.TokenRequestEndpointUrl = "http://tokenUrl"; ExceptionAssert.IsThrowing(new SalesforceException(SalesforceError.AuthenticationFailure, "authentication failed"), () => { target.Authenticate(); }); }
static void Main(string[] args) { // See the SalesforceSetupWalkthrough.doc for information on how to configure your SalesForce account // from your setup >> create >> apps >> connected apps settings in SalesForce const string sfdcConsumerKey = "3MVG9JZ_r.QzrS7gHCcJexYMP2UL45ZgzaagHsVXfYSjWwlhU7n2uaxzfsuBNvwjofV70lM9QtA_xYLTxXjgf"; const string sfdcConsumerSecret = "2968907211720668629"; // your user credentials in salesforce const string sfdcUserName = "******"; const string sfdcPassword = "******"; // your security token form salesforce. Name >> My Settings >> Personal >> Reset My Security Token const string sfdcToken = "w7UGcyJnOaWX8U7XRCEbIfLYw"; var client = new SalesforceClient(); var authFlow = new UsernamePasswordAuthenticationFlow(sfdcConsumerKey, sfdcConsumerSecret, sfdcUserName, sfdcPassword + sfdcToken); // all actions should be in a try-catch - i'll just do the authentication one for an example try { client.Authenticate(authFlow); } catch (SalesforceException ex) { Console.WriteLine("Authentication failed: {0} : {1}", ex.Error, ex.Message); } // create a record using a class instance SFCaseUpdate myCase = new SFCaseUpdate(); myCase.Subject = "This is the subject of my salesforce case"; myCase.Description = "This is the description of my salesforce case"; myCase.Rank__c = 5; client.Create("Case", myCase); // create a record using an anonymous class and returns the ID string resultID = client.Create("Case", new { Subject = "This is the subject of another salesforce case", Description = "This is the description of that other salesforce case", Rank__c = 5 }); // query records var records = client.Query<SFCase>("SELECT id, CaseNumber, Subject, Description, Rank__c FROM Case"); foreach (var r in records) { Console.WriteLine("Query Records {0}: {1} {2}", r.id, r.CaseNumber, r.Subject); } // find the record we just added by the ID we captured above in resultID var record = client.FindById<SFCase>("Case", resultID); Console.WriteLine("\n\nRead this record {0} {1} {2} {3} {4}\n\n", record.id, record.CaseNumber, record.Subject, record.Description, record.Rank__c); // update that record and set the custom field rank to 1 using an anonymous class. client.Update("Case", resultID, new { Rank__c = 1 }); // update that record and set the custom field rank to 9001 using a class instance, note that i have to fill in every property from the record or it will push back nulls SFCaseUpdate myupdate = new SFCaseUpdate(); myupdate.Rank__c = 9001; myupdate.Description = record.Description; myupdate.Subject = record.Subject; client.Update("Case", resultID, myupdate); // re-read it to see if it updated correctly, rank should = 9001 var record2 = client.FindById<SFCase>("Case", resultID); Console.WriteLine("Read this record again {0} {1} {2} {3} {4}\n\n", record2.id, record2.CaseNumber, record2.Subject, record2.Description, record2.Rank__c); // now delete the record I added client.Delete("Case", resultID); Console.WriteLine("Hit Enter to Exit"); Console.ReadKey(); }
private UsernamePasswordAuthenticationFlow CreateAuthenticationFlow(string clientId, string clientSecret, string username, string password) { var flow = new UsernamePasswordAuthenticationFlow(clientId, clientSecret, username, password); flow.TokenRequestEndpointUrl = TestConfig.TokenRequestEndpointUrl; return flow; }
public void Constructor_NoRestClient_DefaultValues() { var target = new UsernamePasswordAuthenticationFlow("clientId", "clientSecret", "username", "password"); Assert.IsNotNull(target); }