Improve "Private App" API usage
まだ誰も着手していません。
評価
調査の方向性
src/Clients/Rest.php のアクセストークンヘッダー周辺から始め、Context::initialize とその初期化チェックを追跡します。記載されているデフォルト値とロギング動作を含め、意図された直接的な Rest($domain, $storeApiToken) フローを確認し、そのうえで既存の API 動作とテストが引き続き成功することを検証します。
索引モデルが issue の本文から書いたものです。
説明
Overview/summary
Currently using this library when connecting to a private app is confusing.
It takes quite a long time to work out what you are doing, when it feels like it could be really simple.
Motivation
In our usecase, we only want to consume the Shopify admin api via REST, with a private app access token.
Currently to do that you have to have the following code:
Context::initialize(
'xxx', // Not used
'yyy', // Not used
'read_orders, write_orders', // Not used
'http://localhost', // Not used
new FileSessionStorage('/tmp/php_sessions'), // Not used
'latest',
false, // Not used
false, // Needs to (incorrectly) be set to false
);
$rest = new Rest($domain, $storeApiToken);
This is not helped by the fact that there is a bug on this line:
https://github.com/Shopify/shopify-php-api/blob/main/src/Clients/Rest.php#L46
So you actually have to Context::initialize with "privateApp" to to false, so it uses the access token not the secret key.
$headers[HttpHeaders::X_SHOPIFY_ACCESS_TOKEN] =
Context::$IS_PRIVATE_APP ? Context::$API_SECRET_KEY : $this->accessToken;
There is barely any point in having to call Context::initialize, the only reason for doing it is to:
- Set Context::$IS_INITIALIZED (to prevent an exception)
- Default Context::$HTTP_CLIENT_FACTORY = new HttpClientFactory();
In an ideal situation I would just need to do this:
$rest = new Rest($domain, $storeApiToken);
Possible Improvements
- Remove the need to call Context::initialize
- Default the API version to 'unstable'
- Default the initialization of $HTTP_CLIENT_FACTORY if null
- Don't throw an exception during log if not initialized
Happy to contribute these changes, if you are welcome to receive them.
- 主要言語
- PHP
- スター
- 473
- フォーク
- 193
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
似ている issue
-
sync-en
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
メンテナーはふだん 1 日以内に返信
-
sync-en
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 4 日以内に返信
-
Перевод устарел
難易度 1/5 1時間未満 初心者へのやさしさ 85/100
-
bug
難易度 2/5 半日 初心者へのやさしさ 76/100
m3ue/m3u-editor#1604 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
femiwiki/docker-mediawiki#1497 ·
メンテナーはふだん 1 日以内に返信