Improve "Private App" API usage
还没有人认领这个 Issue。
评估
调研方向
从 src/Clients/Rest.php 中 access-token header 附近开始,跟踪 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 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
相似的 Issue
-
难度 1/5 1 小时以内 新手友好度 78/100
backdrop-contrib/commerce#60 ·
-
难度 1/5 1 小时以内 新手友好度 76/100
-
难度 1/5 1 小时以内 新手友好度 84/100
TYPO3-Documentation/TYPO3CMS-Reference-CoreApi#7330 ·
维护者通常 1 天内回复
-
dependencies
难度 2/5 1-3 小时 新手友好度 67/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100