feat(twitch): Add Twitch token refresh#144
Merged
Merged
Conversation
jamiepine
approved these changes
Feb 22, 2026
rktmeister
pushed a commit
to rktmeister/spacebot
that referenced
this pull request
Mar 11, 2026
feat(twitch): Add Twitch token refresh
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.
Summary
This PR integrates Twitch token refreshing into Spacebot using
twitch-irc’sRefreshingLoginCredentials, adds persistent storage of Twitch access/refresh tokens,The end result:
Details
Twitch token storage and refreshing
Implemented
TwitchTokenStorageininterface/src/components/ChannelEditModal.tsxas aTokenStorageforRefreshingLoginCredentials:access_token: Stringrefresh_token: Stringtoken_path: Option<PathBuf>load_token():token_pathis set and the file exists, readtwitch_token.jsonand load:access_tokenrefresh_tokencreated_at: Option<DateTime<Utc>>expires_at: Option<DateTime<Utc>>TwitchTokenFiletotwitch_token.jsoncontaining:access_tokenrefresh_tokencreated_at(either the stored time or now)expires_at(if known)UserAccessTokenwith those fields.update_token():twitch-ircwhen refresh succeeds.access_token/refresh_tokenand timestamps fromUserAccessToken.twitch_token.jsonwith the new values.Switched Twitch IRC client creation to
RefreshingLoginCredentials<TwitchTokenStorage>:oauth:prefix if present).TwitchTokenStoragewith:access_tokenfrom configrefresh_tokenfrom config/UI ortwitch_token.jsontoken_pathpointing at~/.spacebot/twitch_token.jsonfor the active instance dir.RefreshingLoginCredentials::init(client_id, client_secret, storage)to lettwitch-irc:client_id/client_secretto call Twitch’s/oauth2/token.update_token()implementation.Extended
TwitchTokenFileto include timing metadata:created_at: Option<DateTime<Utc>>expires_at: Option<DateTime<Utc>>Adapter construction and token file path
Standardized the token file name and path:
token_path = instance_dir.join("twitch_token.json")src/main.rs)src/api/messaging.rs)src/api/bindings.rs)src/config.rs)Updated
TwitchAdapter::newsignature and all call sites to pass:usernameoauth_tokenclient_idclient_secretrefresh_tokentoken_path(Some(instance_dir.join("twitch_token.json")))channelstrigger_prefixpermissions(Arc<ArcSwap<TwitchPermissions>>)Config and API wiring
[messaging.twitch]now supports:usernameoauth_tokenclient_idclient_secretrefresh_tokenchannels = ["..."]trigger_prefixplatform_credentialsfor Twitch now includes:twitch_usernametwitch_oauth_tokentwitch_client_idtwitch_client_secrettwitch_refresh_tokenUI updates (Twitch credentials)
ChannelEditModalTwitch section ininterface/src/components/ChannelEditModal.tsx:handleSaveCredentials()populatesplatform_credentialswith:twitch_usernametwitch_oauth_tokentwitch_client_idtwitch_client_secrettwitch_refresh_tokenchat:readandchat:writescopes must be enabled.