KnpLabs / KnpLabs/php-github-api

Caching requests while authenticating as an Integration

未關閉
#947 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
PHP
星號
2.2k
分支
587
PR 合併指標
30 天內沒有已合併 PR

描述

Not sure if this is a bug or something which should be added to the documentation.
When caching requests the cache key is based on a couple of request headers (https://github.com/KnpLabs/php-github-api/pull/558). I'm assuming this works fine when using `AUTH_ACCESS_TOKEN` for authentication as this token does not change.

When authenticating as an integration it's required to include a JSON Web Token which is valid for a few seconds up to a couple of minutes (I think 10 minutes is the limit). I'm always including a new JWT token which works fine but I'm guessing this is causing trouble with caching since the cache key is changing on every request because the Authorization header has changed (new JWT token).

Replacing the Authorization header on the HeaderCacheKeyGenerator with the installation id seems like a good alternative:

```php
$builder = new Builder();
$builder->addHeaderValue('Installation-id', $installationId);

$client = new Client($builder, 'machine-man-preview');
$client->addCache($pool, [
'cache_key_generator' => new HeaderCacheKeyGenerator([
'Installation-id',
'Cookie',
'Accept',
'Content-type',
]),
]
);
```

Not sure if there is a better alternative to fix this.
Let me know if you want me to create PR to update the documentation.

貢獻指南

這個儲存庫沒有索引到貢獻指南

研究方向

Start by reading HeaderCacheKeyGenerator and the caching context from pull request #558. Reproduce caching with rotating JWT Authorization headers and an installation ID, then determine whether the intended outcome is a documented limitation or a changed cache-key behavior.

由索引模型根據 Issue 內容生成。

評估

技術堆疊
github, php
領域
api, authentication
Issue 類型
缺陷
難度
4/5
預估耗時
3-5 天
活躍度
停滯
描述清晰度
需要釐清
新手友好度
25/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。