PHP code example of stevenmaguire / oauth2-salesforce

1. Go to this page and download the library: Download stevenmaguire/oauth2-salesforce library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

stevenmaguire / oauth2-salesforce example snippets


$provider = new Stevenmaguire\OAuth2\Client\Provider\Salesforce([
    'clientId'          => '{salesforce-client-id}',
    'clientSecret'      => '{salesforce-client-secret}',
    'redirectUri'       => 'https://example.com/callback-url',
    'domain'            => '{custom-salesforce-domain}' // optional, defaults to https://login.salesforce.com
]);

$provider = new Stevenmaguire\OAuth2\Client\Provider\Salesforce([
    'clientId'          => '{salesforce-client-id}',
    'clientSecret'      => '{salesforce-client-secret}',
    'redirectUri'       => 'https://example.com/callback-url'
]);

$existingAccessToken = getAccessTokenFromYourDataStore();

if ($existingAccessToken->hasExpired()) {
    $newAccessToken = $provider->getAccessToken('refresh_token', [
        'refresh_token' => $existingAccessToken->getRefreshToken()
    ]);

    // Purge old access token and store new access token to your data store.
}

$provider->setDomain('https://foo-bar.salesforce.com');