<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
dmt-software / salesforce-oauth-middleware example snippets
use DMT\Salesforce\Auth\Authorization\SalesforceAuthorization;
use DMT\Auth\AuthorizationMiddleware;
use GuzzleHttp\Client;
use GuzzleHttp\Handler\CurlHandler;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Middleware;
use Stevenmaguire\OAuth2\Client\Provider\Salesforce;
$oAuthProvider = new Salesforce(
[
'clientId' => 'YourCustomedKey',
'clientSecret' => 'YourCustomerSecret',
'redirectUri' => 'https://localhost', // wont be visited for grant_type password
]
);
$authMiddleware = new AuthorizationMiddleware(
new SalesforceAuthorization($oAuthProvider, 'YourUsername', 'YourPasswordAmdSecret')
);
$stack = new HandlerStack();
$stack->setHandler(new CurlHandler());
$stack->push(Middleware::mapRequest($authMiddleware));
$client = new Client([
'handler' => $stack
]);
// request will be authorized and routed to your client (sub)domain according to the instance_url received from OAuth
$response = $client->get('https://salesforce.com/services/data/v26.0/sobjects/Account');
use DMT\Salesforce\Auth\Authorization\SalesforceAuthorization;
use DMT\Auth\AuthorizationMiddleware;
use Psr\SimpleCache\CacheInterface;
use Stevenmaguire\OAuth2\Client\Provider\Salesforce;
/** @var Salesforce $oAuthProvider */
/** @var CacheInterface $dataCache */
$authMiddleware = new AuthorizationMiddleware(
new SalesforceAuthorization($oAuthProvider, 'YourUsername', 'YourPasswordAmdSecret', $dataCache)
);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.