XAMPPRocky / octocrab

A modern, extensible GitHub API Client for Rust.
Other
1.09k stars 262 forks source link

Installation tokens are hard to re-use #435

Open marcusirgens opened 1 year ago

marcusirgens commented 1 year ago

It is hard to re-use installation tokens, because (as far as I can tell,) it is not possible to mutate the auth state of the client, nor possible to extract the active installation token. Additionally, the installation auth state does not cache expiration times, installation ID or other data required to renew itself, so it times out after a while.

Would you be interested in a PR that changes any of these issues? My suggestions would be:

XAMPPRocky commented 1 year ago

Change the data structure for AuthState's installation variant to hold the expiration time and installation ID, and re-fetch an installation token if it is about to expire (for octocrab-managed caching).

Thank you for your issue! I think I would lean towards this, because ideally with a high-level client, this would be an implementation detail you shouldn't need to worry about.

marcusirgens commented 1 year ago

I think I would lean towards this, because ideally with a high-level client, this would be an implementation detail you shouldn't need to worry about.

I agree, it would essentially behave like Go's OAuth2 client middleware in that case. It should be orthagonal with the two other points, ie., all three should be possible to do at the same time.

XAMPPRocky commented 1 year ago

all three should be possible to do at the same time.

Sounds good to me 🙂

flying-sheep commented 6 months ago

/edit ignore, this was about my clock not being set correctly and time drift >1min having pushed the expiration date too far into the future.