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
- Host: GitHub
- URL: https://github.com/dmt-software/salesforce-oauth-middleware
- Owner: dmt-software
- License: mit
- Created: 2018-05-24T14:42:09.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2019-02-11T20:13:23.000Z (about 7 years ago)
- Last Synced: 2024-12-01T15:12:09.308Z (over 1 year ago)
- Topics: oauth, psr-7, salesforce
- Language: PHP
- Homepage:
- Size: 16.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Salesforce-OAuth-Middleware
[](https://travis-ci.org/dmt-software/salesforce-oauth-middleware)
[](https://scrutinizer-ci.com/g/dmt-software/salesforce-oauth-middleware/?branch=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