stevenmaguire/oauth2-salesforce

Salesforce OAuth 2.0 Client Provider for The PHP League OAuth2-Client

2.0.1 2017-02-03 19:23 UTC

This package is auto-updated.

Last update: 2024-10-14 11:06:12 UTC


README

Latest Version Software License Build Status Coverage Status Quality Score Total Downloads

This package provides Salesforce OAuth 2.0 support for the PHP League's OAuth 2.0 Client.

Installation

To install, use composer:

composer require stevenmaguire/oauth2-salesforce

Usage

Usage is the same as The League's OAuth client, using \Stevenmaguire\OAuth2\Client\Provider\Salesforce as the provider.

Authorization Code Flow

$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
]);

For further usage of this package please refer to the core package documentation on "Authorization Code Grant".

Refreshing a Token

$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.
}

Using a custom Salesforce domain

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

For further usage of this package please refer to the core package documentation on "Refreshing a Token".

Testing

$ ./vendor/bin/phpunit

Contributing

Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see License File for more information.