This package provides Digi-Key OAuth 2.0 support for the PHP League's OAuth 2.0 Client for use in accessing Digi-Key API Solutions.
To install, use composer:
composer require bggardner/oauth2-digikey:dev-master
Usage is the same as The League's OAuth client, using \Bggardner\OAuth2\Client\Provider\DigiKey
as the provider.
$provider = new Bggardner\OAuth2\Client\Provider\DigiKey([
'clientId' => '{digikey-client-id}',
'clientSecret' => '{digikey-client-secret}',
'redirectUri' => 'https://example.com/callback-url',
'isSandbox' => true, // Optional, defaults to false. When true, client uses sandbox urls.
'localeSite' => 'US', // Optional, defaults to null. Two letter code for Digi-Key product website to search on.
'localeLanguage' => 'en', // Optional, defaults to null. Two letter code for language to search on. Language must be supported by the selected site.
'localeCurrency' => 'USD', // Optional, defaults to null. Three letter code for Currency to return part pricing for. Currency must be supported by the selected site.
'customerId' => '{digikey-customer-id}', // Optional, defaults to null. Your Digi-Key Customer id. If your account has multiple Customer Ids for different regions, this allows you to select one of them.
]);
For further usage of this package please refer to the core package documentation on "Authorization Code Grant".
$provider = new Bggardner\OAuth2\Client\Provider\DigiKey([
'clientId' => '{digikey-client-id}',
'clientSecret' => '{digikey-client-secret}',
'redirectUri' => 'https://example.com/callback-url'
]);
$accessToken = getAccessTokenFromYourDataStore();
if ($accessToken->hasExpired()) {
$accessToken = $provider->getAccessToken('refresh_token', [
'refresh_token' => $accessToken->getRefreshToken()
]);
// Purge old access token and store new access token to your data store.
}
For further usage of this package please refer to the core package documentation on "Refreshing a Token".
The example below makes a request to the Product Details API:
$request = $provider->getAuthenticatedRequest(
'GET',
'https://api.digikey.com/Search/v3/Products/{digikey-part-number}',
$accessToken
);
# Response returns an associative array
$response = $provider->getParsedResponse($request);
The MIT License (MIT). Please see License File for more information.