PHPackages                             frankkessler/salesforce-laravel-oauth2-rest - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. frankkessler/salesforce-laravel-oauth2-rest

ActiveProject[HTTP &amp; Networking](/categories/http)

frankkessler/salesforce-laravel-oauth2-rest
===========================================

A Salesforce REST api wrapper utilizing oAuth2

v0.4.20(9y ago)1918.8k14[5 issues](https://github.com/frankkessler/salesforce-laravel-oauth2-rest/issues)[4 PRs](https://github.com/frankkessler/salesforce-laravel-oauth2-rest/pulls)MITPHPPHP &gt;=5.5.9

Since Oct 25Pushed 6y ago3 watchersCompare

[ Source](https://github.com/frankkessler/salesforce-laravel-oauth2-rest)[ Packagist](https://packagist.org/packages/frankkessler/salesforce-laravel-oauth2-rest)[ RSS](/packages/frankkessler-salesforce-laravel-oauth2-rest/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (11)Versions (42)Used By (0)

[![Travis CI Build Status](https://camo.githubusercontent.com/17ce7aceffdb8739b01fd850ed4f0b2c2d88d89ef0dd5a76ba7692128ee276d2/68747470733a2f2f6170692e7472617669732d63692e6f72672f6672616e6b6b6573736c65722f73616c6573666f7263652d6c61726176656c2d6f61757468322d726573742e737667)](https://travis-ci.org/frankkessler/salesforce-laravel-oauth2-rest/)[![Coverage Status](https://camo.githubusercontent.com/83c0b2c05056bbe97e878775dbdf6d001a7b49d4fd9f960250657fbb036b06c7/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6672616e6b6b6573736c65722f73616c6573666f7263652d6c61726176656c2d6f61757468322d726573742f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/frankkessler/salesforce-laravel-oauth2-rest?branch=master)[![StyleCI](https://camo.githubusercontent.com/2b9a2e49d5cf0505293f6a65d510435476babf3e0f85d94a50b81dd6f234d8f5/68747470733a2f2f7374796c6563692e696f2f7265706f732f34323436353033342f736869656c64)](https://styleci.io/repos/42465034)[![Latest Stable Version](https://camo.githubusercontent.com/d583e99ae574b2820cb00ddf78f6dea527e1ab3e6fb866d96d9de2a886c20b99/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6672616e6b6b6573736c65722f73616c6573666f7263652d6c61726176656c2d6f61757468322d726573742e737667)](https://packagist.org/packages/frankkessler/salesforce-laravel-oauth2-rest)

RUNNING UNIT TESTS
==================

[](#running-unit-tests)

There are currently two ways to run the unit tests. Keep in mind that node is a dependency for running the unit tests regardless of which way you want to run them.

If you have make installed you can run

```
make tests

```

If you would prefer to see more details about how the unit tests run, you can start the node server and then run the unit tests from another window.

```
node tests/server.js 8126 true

```

Then in a different window:

```
vendor/bin/phpunit

```

INSTALLATION
============

[](#installation)

To install this package, add the following to your composer.json file

```
"frankkessler/salesforce-laravel-oauth2-rest": "0.4.*"
```

LARAVEL 5 SPECIFIC INSTALLATION TASKS
-------------------------------------

[](#laravel-5-specific-installation-tasks)

Add the following to your config/app.php file in the providers array

```
Frankkessler\Salesforce\Providers\SalesforceLaravelServiceProvider::class,
```

Add the following to your config/app.php file in the aliases array

```
'Salesforce'    => Frankkessler\Salesforce\Facades\Salesforce::class,
```

Run the following command to pull the project config file and database migration into your project

```
php artisan vendor:publish
```

Run the migration

```
php artisan migrate
```

\##OPTIONAL INSTALLATION

Logging is enabled by default if using Laravel. If not, add the following to the $config parameter when initializing the Salesforce class. (This class must implement the Psr\\Log\\LoggerInterface interface.)

```
'salesforce.logger' => $class_or_class_name
```

\#TOKEN SETUP

Currently, this package only supports the web server flow (Authorization Code) and JWT Web Tokens for oauth2.

Web Server Flow Setup (Authorization Code)
------------------------------------------

[](#web-server-flow-setup-authorization-code)

This utilizes access and refresh tokens in order to grant access.

To get started, you'll have to setup a Connected App in Salesforce.

1. Navigate to Setup -&gt; Create -&gt; Apps
2. In the Connected Apps section, click New
3. Fill out the form including the Api/Oauth section.
4. Your callback URL must be https and will follow this format:
5. Save and wait 10 minutes for the settings to save.

Now that you have your Client Id and Client secret, add them to your .env file:

```
SALESFORCE_API_DOMAIN=na1.salesforce.com
SALESFORCE_OAUTH_CALLBACK_URL=https://yourdomain.com/salesforce/callback
SALESFORCE_OAUTH_DOMAIN=login.salesforce.com
SALESFORCE_OAUTH_CONSUMER_TOKEN=YOUR_CLIENT_ID_FROM_CREATED_APP
SALESFORCE_OAUTH_CONSUMER_SECRET=YOUR_CLIENT_SECRET_FROM_CREATED_APP
```

To login and authorize this application add the following to your routes.php file. You may remove these routes once you have your refresh token stored in the database.

```
Route::get('salesforce/login', '\Frankkessler\Salesforce\Controllers\SalesforceController@login_form');
Route::get('salesforce/callback', '\Frankkessler\Salesforce\Controllers\SalesforceController@process_authorization_callback');
```

Visit  to authorize your application. Your access token and refresh token will be stored in the salesforce\_tokens database table by default.

JWT Web Token
-------------

[](#jwt-web-token)

Setup your public and private key pair. Salesforce recommends you use an RSA 256 key. Here is a sample script that will generate a key for you in PHP.

```
$privateKeyPassphrase = null;
$csrString = '';
$privateKeyString = '';
$certString = '';

$config = [
    'private_key_type' => \OPENSSL_KEYTYPE_RSA,
    'digest_alg' => 'sha256',
    'private_key_bits' => 2048,
];

$dn = array(
    "countryName" => "US",
    "stateOrProvinceName" => "New York",
    "localityName" => "New York",
    "organizationName" => "SalesforceLaravel",
    "organizationalUnitName" => "SalesforceLaravel",
    "commonName" => "SalesforceLaravel",
    "emailAddress" => "SalesforceLaravel@example.com"
);

$privateKey = openssl_pkey_new($config);

$csr = openssl_csr_new($dn, $privateKey);

$sscert = openssl_csr_sign($csr, null, $privateKey, 365);

openssl_csr_export($csr, $csrString);
file_put_contents(__DIR__.'/../csr.csr', $csrString);

openssl_x509_export($sscert, $certString);
file_put_contents(__DIR__.'/../public.crt', $certString);

openssl_pkey_export($privateKey, $privateKeyString, $privateKeyPassphrase);
file_put_contents(__DIR__.'/../private.key', $privateKeyString);

```

Setup your app in Salesforce:

1. Navigate to Setup -&gt; Create -&gt; Apps
2. In the Connected Apps section, click New
3. Fill out the form including the Api/Oauth section.
4. Your callback URL must be https and will follow this format:
5. Check off "Use Digital Signature" and upload the PUBLIC key (public.crt) generated in the previous section.
6. Select the Oauth scopes you want, but make sure you select the refresh\_token, offline\_access scope or this flow will fail.
7. Save
8. To get up and running as quick as possible you can follow the next few steps, but they might not work for everyone.
9. Navigate to Setup -&gt; Manage Apps -&gt; Connected Apps and click on the App you just created
10. Click edit and select "Admin approved users are pre-authorized" in the Permitted users field
11. Click Save
12. Scroll down on the same page and select the Manage Profiles button to add the profiles that are pre-authorized to use JWT Web Tokens in your app

Add the following variables to your .env file.

```
SALESFORCE_API_DOMAIN=na1.salesforce.com
SALESFORCE_OAUTH_CALLBACK_URL=https://yourdomain.com/salesforce/callback
SALESFORCE_OAUTH_DOMAIN=login.salesforce.com
SALESFORCE_OAUTH_CONSUMER_TOKEN=YOUR_CLIENT_ID_FROM_CREATED_APP
SALESFORCE_OAUTH_CONSUMER_SECRET=YOUR_CLIENT_SECRET_FROM_CREATED_APP
SALESFORCE_OAUTH_AUTH_TYPE="jwt_web_token"
SALESFORCE_OAUTH_JWT_PRIVATE_KEY="/usr/path/to/my/private.key"
SALESFORCE_OAUTH_JWT_PRIVATE_KEY_PASSPHRASE="testpassword" //optional
SALESFORCE_OAUTH_JWT_RUN_AS_USER_NAME="test.use@mycompanyname.com"  //This is the Salesforce username that will be used to connect

```

EXAMPLES
========

[](#examples)

### Get a sObject record

[](#get-a-sobject-record)

```
$objectType = 'Account';
$objectId = 'OBJECT_ID';

$result = Salesforce::sobject()->get($objectId, $objectType);

if($result->success){
    $name = $result->sobject['Name'];
}
```

### Insert a sObject record

[](#insert-a-sobject-record)

```
$objectType = 'Account';
$objectData = [
    'Name'          => 'Acme',
    'Description'   => 'Account Description',
];

$result = Salesforce::sobject()->insert($objectType, $objectData);

if($result->success){
    $id = $result->id;
}
```

### Update a sObject record

[](#update-a-sobject-record)

```
$objectType = 'Account';
$objectId = 'OBJECT_ID';
$objectData = [
    'Name'          => 'Acme',
    'Description'   => 'Account Description',
];

$result = Salesforce::sobject()->update($objectId, $objectType, $objectData);

if($result->success){
    //no data returned
}
```

### Delete a sObject record

[](#delete-a-sobject-record)

```
$objectType = 'Account';
$objectId = 'OBJECT_ID';

$result = Salesforce::sobject()->delete($objectId, $objectType);

if($result->success){
    //no data returned
}
```

### Perform a SOQL Query

[](#perform-a-soql-query)

```
$soql = 'SELECT Id, Name FROM Account LIMIT 1';

$result = Salesforce::query()->query($soql);

if($result->success && $result->totalSize > 0){
    foreach($result->records as $record){
        $account_name = $record['Name'];
    }
}
```

### Perform a SOQL Query that will get all the records

[](#perform-a-soql-query-that-will-get-all-the-records)

```
//since all records are grabbed at once and all records will be in memory, test the max size of the data you would like to use with this function before running in production.  Large data sets could throw PHP OUT OF MEMORY errors.

$soql = 'SELECT Id, Name FROM Account LIMIT 1';

$result = Salesforce::query()->queryFollowNext($soql);

if($result->success && $result->totalSize > 0){
    foreach($result->records as $record){
        $account_name = $record['Name'];
    }
}
```

### Perform a SOSL Query

[](#perform-a-sosl-query)

```
$sosl = 'FIND {Acme} IN ALL FIELDS RETURNING Account(Id, Name ORDER BY LastModifiedDate DESC LIMIT 3)';

$result = Salesforce::query()->search($sosl);

if($result->success && $result->totalSize > 0){
    foreach($result->records as $record){
        $account_name = $record['Name'];
    }
}
```

Bulk Api Processing
-------------------

[](#bulk-api-processing)

### Insert

[](#insert)

```
$operationType = 'insert';
$objectType = 'Account';
$objectData = [
    [
        'Name'          => 'Acme',
        'Description'   => 'Account Description',
    ],
    [
        'Name'          => 'Acme2',
        'Description'   => 'Account Description2',
    ],
];

$result = Salesforce::bulk()->runBatch($operationType, $objectType, $objectData);

if($result->id){
    $id = $result->id;
}
```

### Upsert

[](#upsert)

```
$operationType = 'upsert';
$objectType = 'Account';
$objectData = [
    [
        'ExternalId__c' => 'ID1',
        'Name'          => 'Acme',
        'Description'   => 'Account Description',
    ],
    [
        'ExternalId__c' => 'ID2',
        'Name'          => 'Acme2',
        'Description'   => 'Account Description2',
    ],
];

$result = Salesforce::bulk()->runBatch($operationType, $objectType, $objectData, ['externalIdFieldName' => 'ExternalId__c']);

if($result->id){
    foreach ($result->batches as $batch) {
        echo $batch->numberRecordsProcessed;
        echo $batch->numberRecordsFailed;
        foreach ($batch->records as $record) {
            if(!$record['success']){
                echo 'Record Failed: '.json_encode($record);
            }
        }
    }
}
```

### Query

[](#query)

```
$operationType = 'query';
$objectType = 'Account';
$objectData = 'SELECT Id, Name FROM Account LIMIT 10';

$result = Salesforce::bulk()->runBatch($operationType, $objectType, $objectData);

if ($result->id) {
    $id = $result->id;
    foreach ($result->batches as $batch) {
        foreach ($batch->records as $record) {
            $account_id = $record['Id'];
        }
    }
}
```

### Query with PK Chunking

[](#query-with-pk-chunking)

```
$operationType = 'query';
$objectType = 'Account';
$objectData = 'SELECT Id, Name FROM Account';

$result = Salesforce::bulk()->runBatch($operationType, $objectType, $objectData, [
    'contentType' => 'CSV',
    'Sforce-Enable-PKChunking' => [
        'chunkSize' => 2500,
    ],
]);

if ($result->id) {
    $id = $result->id;
    foreach ($result->batches as $batch) {
        foreach ($batch->records as $record) {
            $account_id = $record['Id'];
        }
    }
}
```

### Query with Class to Process each Batch

[](#query-with-class-to-process-each-batch)

```
$operationType = 'query';
$objectType = 'Account';
$objectData = 'SELECT Id, Name FROM Account LIMIT 10';

$result = Salesforce::bulk()->runBatch($operationType, $objectType, $objectData,[
    'batchProcessor' => CustomBulkBatchProcessor::class, //Class must implement Frankkessler\Salesforce\Interfaces\BulkBatchProcessorInterface
]);

if ($result->id) {
    $id = $result->id;
}
```

### Custom REST Endpoint (GET)

[](#custom-rest-endpoint-get)

```
$uri = 'custom_apex_uri_get';

$result = Salesforce::custom()->get($uri);

if($result->http_status == 200){
    $body = $result->raw_body;
}
```

### Custom REST Endpoint (POST)

[](#custom-rest-endpoint-post)

```
$uri = 'custom_apex_uri_post';

$result = Salesforce::custom()->post($uri);

if($result->http_status == 200){
    //success
}
```

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance15

Infrequent updates — may be unmaintained

Popularity34

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~13 days

Total

38

Last Release

3358d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/80184c74c57baaff6ac4e3ef7152c2db3d79719f69fafe1fdcc346f4837a402a?d=identicon)[frankkessler](/maintainers/frankkessler)

---

Top Contributors

[![frankkessler](https://avatars.githubusercontent.com/u/1131687?v=4)](https://github.com/frankkessler "frankkessler (173 commits)")

---

Tags

restoauth2salesforce

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/frankkessler-salesforce-laravel-oauth2-rest/health.svg)

```
[![Health](https://phpackages.com/badges/frankkessler-salesforce-laravel-oauth2-rest/health.svg)](https://phpackages.com/packages/frankkessler-salesforce-laravel-oauth2-rest)
```

###  Alternatives

[omniphx/forrest

A Laravel library for Salesforce

2724.4M8](/packages/omniphx-forrest)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[api-platform/laravel

API Platform support for Laravel

59126.4k6](/packages/api-platform-laravel)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)[laravel/cashier-paddle

Cashier Paddle provides an expressive, fluent interface to Paddle's subscription billing services.

264778.4k3](/packages/laravel-cashier-paddle)[dragon-code/laravel-http-logger

Logging incoming HTTP requests

319.8k3](/packages/dragon-code-laravel-http-logger)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
