Repository navigation
feat(games): get a Twitch app token for IGDB - #181
Merged
Merged
Conversation
IGDB takes a Twitch app access token, so the games service gets one with the client credentials grant, keeps it in memory until 9 tenths of its life, asks Twitch one request at a time, and forgets a token that IGDB refuses. Nothing uses it yet: igdb-search will. Records decision 304.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Brief
Goal: the
gamesservice can get a Twitch app token for IGDB, keep it, and renew it before it expires (decision 68): the fifth ofgames-exophase's eleven steps.Scope: a new package,
services/games/internal/twitch. It asks Twitch's OAuth server for an app access token with the client credentials grant, keeps the token in memory, and renews it before it expires. It also forgets a token that IGDB refuses. Decision 304 and the step's rows in plan §0 and §8.2 come with it.Out of scope:
igdb-search);games-covers);homelab-games).Acceptance criteria:
TokenasksPOST /oauth2/tokenwithclient_id,client_secretandgrant_type=client_credentialsin a form body, with nothing in the query. It returns the token from the answer.expires_inhave passed, counted from when the request began. After that, the next call asks for a new one.Dropforgets the token that IGDB refused. A token that is no longer the one kept changes nothing.get a Twitch token:and the status, with Twitch'smessagewhen there is one. An answer with no token, a lifetime of 0 seconds or less, a body that isn't JSON, or a body over 64 KiB givesread Twitch's answer:.mise run checkis green.What changed
services/games/internal/twitch/tokens.go:Tokenskeeps the latest token and takes turns through a one-slot channel.Tokenreturns the kept token or gets a new one, andDropforgets a refused one.services/games/internal/twitch/app.go:Newgives theTokensof a Twitch app. Its request sends the form, reads the token and its lifetime, and says why Twitch refused.tokens_internal_test.go: a fake Twitch, in synctest bubbles;app_internal_test.go: an in-memory Twitch for the lifetime and the 10 seconds, in bubbles;app_test.go: anhttpteststand-in for the request and the errors.docs/plan.md: decision 304, the §0 row and the §8.2 bullet.QA
-race.http.NewRequestWithContext's error, which a parsed URL and a fixed method never hit.Dropwithout the turn, leaves the same token behind. Only the race detector catches it, whichmise run testruns.expires_insays, in seconds;Dropwaits for a token that's on its way;Accepttoo.https://id.twitch.tvgivesget a Twitch token: 400 Bad Request, invalid client.mise run checkpassed on this branch's tree, merged withmainafter refactor(notes): keep a note page's state in a class #177 and feat(games): serve the games I played lately #178:Review
Droptakes no context. It waits for a request under way, which takes at most 10 seconds.selectpicks either case. So such a call may still return the kept token, or fail its request at once. Both are harmless.time.Duration. Twitch gives about 60 days, andDropforgets any token that IGDB refuses.NeworDropyet:igdb-searchandgames-coverswill.Merged under the user's standing OK once CI's
checkis green.