KnpLabs / KnpLabs/php-github-api

Caching requests while authenticating as an Integration

Đang mở
#947 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
PHP
Star
2.2k
Fork
587
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

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.

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
github, php
Lĩnh vực
api, authentication
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Cần làm rõ
Mức phù hợp với người mới
25/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.