tzmfreedom / rustforce

Salesforce REST API Client by Rust
MIT License
41 stars 19 forks source link

Failing authentication #10

Closed sempervictus closed 3 years ago

sempervictus commented 3 years ago

I'm converting some Ruby RestForce code to run standalone in Rust across platforms without runtime dependencies, and running into a bit of a problem:

Failed to tauthenticate due to TokenError(
    TokenErrorResponse {
        error: "invalid_grant",
        error_description: "authentication failure",
    },
)

The code throwing this is:

struct SalesForceParams {
        username:       String,
        password:       String,
        client_id:      String,
        client_secret:  String,
        security_token: String,
        login_endpoint: String,
}
impl SalesForceParams {
    fn test_params() -> Self {
        Self {
            username:       String::from("email@somewhere.nul"),
            password:       String::from("REDACTED"),
            client_id:      String::from("REDACTED"),
            client_secret:  String::from("REDACTED"),
            security_token: String::from("REDACTED"),
            login_endpoint: String::from("https://test.salesforce.com"),
        }
    }
}
...
    let sf_params = SalesForceParams::test_params();
    let mut client = Client::new(sf_params.client_id, sf_params.client_secret);
    client.set_login_endpoint(&sf_params.login_endpoint);
    client.set_access_token(&sf_params.security_token);
    let res = client.login_with_credential(sf_params.username,sf_params.password).await;
    match res {
        Ok(r) => println!("Authenticated successfully"),
        Err(err) => println!("Failed to tauthenticate due to {:#?}", err)
    }

The values for those parameters are ripped out of the Ruby code - copy pasted, and the Ruby version does authenticate correctly. What am i doing wrong here?

sempervictus commented 3 years ago

Apparently RestForce concatenates the access_token and password fields of their input.