Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sf_auth(login_url = ) Bad Request (HTTP 400) #132

Open
rdinter-usda opened this issue Oct 8, 2024 · 5 comments
Open

sf_auth(login_url = ) Bad Request (HTTP 400) #132

rdinter-usda opened this issue Oct 8, 2024 · 5 comments
Assignees
Labels
question or help Clarification or help may suffice to resolve

Comments

@rdinter-usda
Copy link

Issues with authentication for private instance of Salesforce that appears similar to #111 and #108.

> sf_auth(login_url = "https://PRIVATE-INSTANCE.lightning.force.com/")
Waiting for authentication in browser...
Press Esc/Ctrl + C to abort
Authentication complete.
Error in oauth2.0_access_token(endpoint, app, code = code, user_params = user_params,  : 
  Bad Request (HTTP 400). Failed to get an access token.

Authentication appears to work through the browser, however this error shows up in R. What is strange is I can see a file .httr-oauth-salesforcer in working directory that is created and it is roughly 6 bytes. Then when I attempt to try sf_list_reports() another window pops up for authentication, the browser says authentication worked, and once I return to R the report list is displayed.

@StevenMMortimer StevenMMortimer added the question or help Clarification or help may suffice to resolve label Nov 4, 2024
@StevenMMortimer
Copy link
Owner

Is this still an issue @rdinter-usda? Based on what you described, it prompts twice and works the second time?

I will also be switching the package over from {{httr}} to the {{httr2}} package, which maybe could help some of these transient errors if it handles the authentication in a more sophisticated way. I'm not sure.

@rdinter-usda
Copy link
Author

Yes this is still an issue, although I would not say it works the second time. Each time I call sf_auth(login_url = ) it fails with an error. However, if I call other functions used in salesforceR like sf_list_reports() then it succeeds. I believe that's related to some side-effect of cacheing of the oauth.

@StevenMMortimer
Copy link
Owner

Are you accessing your R session on a remote server via the browser? In other words, are you not running it locally on your laptop? Or is it possible that some other process is running on port 1410 of your machine?

According to this article, it sounds like either of those would cause issues like you're seeing and you'd have to try and use out of band authentication. I can try to add those arguments to the sf_auth() function so they can be passed through to {{httr}} package functions.

@rdinter-usda
Copy link
Author

I am using R locally and verified that port 1410 is not being used by any other process, although that article does sound like similar issues to what I am seeing because of the 400 error that is displayed.

@dethmasque
Copy link

I was seeing the same behavior when running salesforcer::sf_auth(login_url="https://example.my.salesforce.com") locally. The error in the URL implied that this is PKCE-related: http://localhost:1410/?error=invalid_request&error_description=missing+required+code+challenge. Turning off PKCE at the organization level resolved the error and allowed for successful authentication:

Screenshot 2024-12-09 at 4 00 59 PM

image

 salesforcer::sf_auth(login_url = "https://example.my.salesforce.com")
Waiting for authentication in browser...
Press Esc/Ctrl + C to abort
Authentication complete.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question or help Clarification or help may suffice to resolve
Projects
None yet
Development

No branches or pull requests

3 participants