定制 bggardner/oauth2-digikey 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

bggardner/oauth2-digikey

Composer 安装命令:

composer require bggardner/oauth2-digikey

包简介

Digi-Key OAuth 2.0 Client Provider for the PHP League OAuth2-Client

README 文档

README

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.

Installation

To install, use composer:

composer require bggardner/oauth2-digikey:dev-master

Usage

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

Authorization Code Flow

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

Refreshing a Token

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

Making an API call

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

License

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

统计信息

  • 总下载量: 883
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-03-24