An open API service indexing awesome lists of open source software.

https://github.com/dmt-software/salesforce-oauth-middleware

Salesforce OAuth 2.0 middleware for REST API calls
https://github.com/dmt-software/salesforce-oauth-middleware

oauth psr-7 salesforce

Last synced: 4 months ago
JSON representation

Salesforce OAuth 2.0 middleware for REST API calls

Awesome Lists containing this project

README

          

# Salesforce-OAuth-Middleware

[![Build Status](https://travis-ci.org/dmt-software/salesforce-oauth-middleware.svg?branch=master)](https://travis-ci.org/dmt-software/salesforce-oauth-middleware)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/dmt-software/salesforce-oauth-middleware/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/dmt-software/salesforce-oauth-middleware/?branch=master)
[![Code Coverage](https://scrutinizer-ci.com/g/dmt-software/salesforce-oauth-middleware/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/dmt-software/salesforce-oauth-middleware/?branch=master)

This authorization middleware uses the OAuth `grant_type` [password](https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/intro_understanding_username_password_oauth_flow.htm)
to authenticate and authorize a request to the Salesforce REST API.

## Install
`composer require dmt-software/salesforce-oauth-middleware`

## Usage

```php
'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');
```
## Cache

To re-use an access token this middleware can be configured with a PSR-16 cache implementation.
```php