Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration manager refactoring & Integration tokens auto refreshing #2949

Open
wants to merge 13 commits into
base: v5
Choose a base branch
from

Conversation

Samuel38
Copy link
Contributor

Description of the Change

  • Typescripting IntegrationManager
  • Typescription AuthAPIController
  • Adding ability to pass options to AuthController to be included in requests
  • Adding client_id and client_secret by default to all requests for OAuth2 code flow
  • Ensuring we use AuthData type for all methods that interact with other modules than AuthManager
  • Expanding AuthData type so we include timestamps for creation and expiry (expires_at is now a timestamp so its type is naturally restored by JSonDb)
  • Fixing refreshTokenIfExpired() so it doesn't always think the token is still valid
  • Renaming obtainmentTimestamp to created_at to be consistent with norm and some providers
  • Fixing some type issues in ExtraLife integration
  • Renaming oauth to auth in IntegrationData so we're consistant across the IntegrationManager
  • Making integrationManager getters generic so integrations can get their data returned with the proper FirebotSettings and integrationDefinition extension types.
  • Creating an abstract integrationController generic type that integrations should extend to ensure compatibility.
  • Adding a refreshToken() method to IntegrationManager to manually ask to refresh a token if autoRefresh isn't enabled.
  • Adding a getAuth() method that attempts to returns a valid LinkData object (auth token or Account ID), auto refreshing the token if enabled and necessary. This should be the preferred method of getting access token.
  • Adding a token-refreshed event emitted by IntegrationManager each one an integration's token is refreshed.
  • Fixing integrationCanConnect() and integrationIsLinked() methods that were pulling from the wrong object.
  • Adding Integration related type definitions.

Applicable Issues

  • Auth tokens not refreshing for integrations
  • auth vs oauth properties confusing to get auth data.
  • Need to typescript IntegrationManager stuff

Testing

  • Firebot connects/disconnects/links properly, whether token is new, is refreshed, or needs to be refreshed after off time.
  • Integration connects/disconnects/links/unlinks properly whether token is new, is refreshed, needs to be refreshed after off time, or is requested to be refreshed manually.
  • getAuth() works with autoRefresh for token.
  • token-refreshed is emitted and can be received by integration
  • integration can define its own aditionnal events
  • integration can use the generics properly

Not tested :

  • I don't use built in integrations, so haven't been able to test it. But there shouldn't be any breaking changes.
  • I don't think changes should break existing integrations, but would be worthwhile testing a few

Fixing a bug in the createToken method of oauth2-client that made it so token was always seen as non expired by having our own createToken method.
Adding the ability to pass options to the oauth2 client to be added with the requests. This allows for Integrations to work with APIs that require certain additional fields (For example Id and Secret in body as required by Tiltify)
Adding a refreshToken() method to IntegrationManager to allow integrations to manually request a refresh token id autoRefresh is disabled.
Adding a getAuth() method to IntegrationManager. Integrations should use this method to get the auth with a valid token to allow the IntegrationManager to autoRefresh the token.
Emitting a "token-refreshed" event when the token is refreshed by either method in case the integration needs to do something with it.
Renaming the oauth property to auth so it is consistent, since both appeared, and consistent with the type definition currently exposed to integrations.
- TS for IntegrationManager
- `IntegrationData` now must contain property `linked`
- `refreshToken()` now returns `AuthData` instead of `IntegrationData`
- TS for AuthAPIController
- Changed `AuthManager` to rely as little as possilbe on `ClientOAuth2` types and more on our own `AuthDetails` type which is better type defined.
- Changed `obtainmentTimestamp` custom `AuthDetails` property which was used by twitch auth to `created_at`, more consistent with the `expires_in` standard one.
- Added `client_id` and `client_secret` by default in the request body to all OAuth requests instead of just initial token request.
- Fixed a few typing and linting mistakes in extralife integration.
- created integrations type file, which exposes IntegrationManager and a generic abstract class for IntegrationController which integrations can inherit to emit their custom events and ensure interfacing with the integrationManager.
- JSonDb properly restores numbers, not Dates, so a timestamp is better stored
- Solving a bug where token created_at and expires_at wouldn't properly refresh when refreshing tokens, leading to chain refreshing.
@Samuel38 Samuel38 requested a review from ebiggz as a code owner December 28, 2024 02:58
@Samuel38
Copy link
Contributor Author

Created related PR in firebot-custom-scripts-types with changes that reflect these.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant