restforcephp icon indicating copy to clipboard operation
restforcephp copied to clipboard

Exception when trying to authenticate with OAuth 2.0 Web Server Flow for Web App Integration

Open Dawnthorn opened this issue 4 months ago • 0 comments

My understanding is for the "OAuth 2.0 Web Server Flow for Web App Integration" you only need the client_id and the client_secret to get an OAuth Token. We tried that like this:

        $this->restforce = new Restforce(
                $salesforce_credentials['client_id'],
                $salesforce_credentials['client_secret'],
                NULL,
                NULL,
                NULL,
                $salesforce_credentials['api_version'],
                $salesforce_credentials['instance_url'],
            );

That throws this exception:

PHP Fatal error:  Uncaught EventFarm\Restforce\RestforceException: Restforce needs either an OAuthToken or User/PW combo to start authenticate in vendor/eventfarm/restforcephp/src/RestforceException.php:15
Stack trace:
#0 vendor/eventfarm/restforcephp/src/Restforce.php(48): EventFarm\Restforce\RestforceException::minimumRequiredFieldsNotMet()
#1 salesforce/SalesforceApi.php(21): EventFarm\Restforce\Restforce->__construct()
#2 foo.php(19): Salesforce\SalesforceApi->getRestforceClient()
#3 [internal function]: test_function()

But, if we take out this check in vendor/eventfarm/restforcephp/src/Restforce.php, then everything works fine:

if ($accessToken === null && $username === null && $password === null) {
    throw RestforceException::minimumRequiredFieldsNotMet();
}

You don't need to start with an access token to use this flow to authenticate with Salesforce, so I'm not sure why that parameter is required.

Dawnthorn avatar Oct 01 '24 19:10 Dawnthorn