diff --git a/packages/backend/src/apps/twitch/assets/favicon.svg b/packages/backend/src/apps/twitch/assets/favicon.svg deleted file mode 100644 index 8adbef1a..00000000 --- a/packages/backend/src/apps/twitch/assets/favicon.svg +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/packages/backend/src/apps/twitch/authentication.ts b/packages/backend/src/apps/twitch/authentication.ts deleted file mode 100644 index 26780bc9..00000000 --- a/packages/backend/src/apps/twitch/authentication.ts +++ /dev/null @@ -1,105 +0,0 @@ -import type { - IAuthentication, - IApp, - IField, - IJSONObject, -} from '@automatisch/types'; -import TwitchApi, { TwitchJsOptions } from 'twitch-js'; -import fetchUtil from 'twitch-js/lib/utils/fetch'; - -type TwitchTokenResponse = { - accessToken: string; - refreshToken: string; - expiresIn: string; - tokenType: string; -}; - -export default class Authentication implements IAuthentication { - appData: IApp; - connectionData: IJSONObject; - client: TwitchApi; - - constructor(appData: IApp, connectionData: IJSONObject) { - this.connectionData = connectionData; - this.appData = appData; - - if (this.clientOptions.token) { - this.client = new TwitchApi(this.clientOptions as TwitchJsOptions); - } - } - - get clientOptions() { - return { - token: this.connectionData.accessToken, - clientId: this.connectionData.consumerKey, - log: { enabled: true }, - }; - } - - get oauthRedirectUrl() { - return this.appData.fields.find( - (field: IField) => field.key == 'oAuthRedirectUrl' - ).value; - } - - async createAuthData() { - const { url } = await fetchUtil('https://id.twitch.tv/oauth2/authorize', { - search: { - client_id: this.connectionData.consumerKey, - redirect_uri: this.oauthRedirectUrl, - response_type: 'code', - scope: 'user:read:email', - }, - }); - - return { url }; - } - - async verifyCredentials() { - const verifiedCredentials = (await fetchUtil( - 'https://id.twitch.tv/oauth2/token', - { - method: 'post', - search: { - client_id: this.connectionData.consumerKey, - client_secret: this.connectionData.consumerSecret, - code: this.connectionData.oauthVerifier, - grant_type: 'authorization_code', - redirect_uri: this.oauthRedirectUrl, - }, - } - )) as TwitchTokenResponse; - - this.connectionData.accessToken = verifiedCredentials.accessToken; - - const { api } = new TwitchApi(this.clientOptions as TwitchJsOptions); - - const { data } = await api.get('users'); - const [user] = data; - - return { - consumerKey: this.connectionData.consumerKey, - consumerSecret: this.connectionData.consumerSecret, - accessToken: verifiedCredentials.accessToken, - refreshToken: verifiedCredentials.refreshToken, - expiresIn: verifiedCredentials.expiresIn, - tokenType: verifiedCredentials.tokenType, - userId: user.id, - screenName: user.displayName, - }; - } - - async isStillVerified() { - try { - await fetchUtil('https://id.twitch.tv/oauth2/userinfo', { - headers: { - Authorization: `Bearer ${this.connectionData.accessToken}`, - }, - }); - - return true; - } catch (err) { - return false; - } - } -} diff --git a/packages/backend/src/apps/twitch/index.d.ts b/packages/backend/src/apps/twitch/index.d.ts deleted file mode 100644 index e69de29b..00000000 diff --git a/packages/backend/src/apps/twitch/index.ts b/packages/backend/src/apps/twitch/index.ts deleted file mode 100644 index 42d13c05..00000000 --- a/packages/backend/src/apps/twitch/index.ts +++ /dev/null @@ -1,15 +0,0 @@ -import Authentication from './authentication'; -import { - IService, - IAuthentication, - IApp, - IJSONObject, -} from '@automatisch/types'; - -export default class Twitch implements IService { - authenticationClient: IAuthentication; - - constructor(appData: IApp, connectionData: IJSONObject) { - this.authenticationClient = new Authentication(appData, connectionData); - } -} diff --git a/packages/backend/src/apps/twitch/info.json b/packages/backend/src/apps/twitch/info.json deleted file mode 100644 index 2931af88..00000000 --- a/packages/backend/src/apps/twitch/info.json +++ /dev/null @@ -1,219 +0,0 @@ -{ - "name": "Twitch", - "key": "twitch", - "iconUrl": "{BASE_URL}/apps/twitch/assets/favicon.svg", - "docUrl": "https://automatisch.io/docs/twitch", - "primaryColor": "2DAAE1", - "supportsConnections": true, - "fields": [ - { - "key": "oAuthRedirectUrl", - "label": "OAuth Redirect URL", - "type": "string", - "required": true, - "readOnly": true, - "value": "{WEB_APP_URL}/app/twitch/connections/add", - "placeholder": null, - "description": "When asked to input an OAuth callback or redirect URL in Twitch OAuth, enter the URL above.", - "docUrl": "https://automatisch.io/docs/twitch#oauth-redirect-url", - "clickToCopy": true - }, - { - "key": "consumerKey", - "label": "Consumer Key", - "type": "string", - "required": true, - "readOnly": false, - "value": null, - "placeholder": null, - "description": null, - "docUrl": "https://automatisch.io/docs/twitch#consumer-key", - "clickToCopy": false - }, - { - "key": "consumerSecret", - "label": "Consumer Secret", - "type": "string", - "required": true, - "readOnly": false, - "value": null, - "placeholder": null, - "description": null, - "docUrl": "https://automatisch.io/docs/twitch#consumer-secret", - "clickToCopy": false - } - ], - "authenticationSteps": [ - { - "step": 1, - "type": "mutation", - "name": "createConnection", - "arguments": [ - { - "name": "key", - "value": "{key}" - }, - { - "name": "formattedData", - "value": null, - "properties": [ - { - "name": "consumerKey", - "value": "{fields.consumerKey}" - }, - { - "name": "consumerSecret", - "value": "{fields.consumerSecret}" - } - ] - } - ] - }, - { - "step": 2, - "type": "mutation", - "name": "createAuthData", - "arguments": [ - { - "name": "id", - "value": "{createConnection.id}" - } - ] - }, - { - "step": 3, - "type": "openWithPopup", - "name": "openAuthPopup", - "arguments": [ - { - "name": "url", - "value": "{createAuthData.url}" - } - ] - }, - { - "step": 4, - "type": "mutation", - "name": "updateConnection", - "arguments": [ - { - "name": "id", - "value": "{createConnection.id}" - }, - { - "name": "formattedData", - "value": null, - "properties": [ - { - "name": "oauthVerifier", - "value": "{openAuthPopup.code}" - } - ] - } - ] - }, - { - "step": 5, - "type": "mutation", - "name": "verifyConnection", - "arguments": [ - { - "name": "id", - "value": "{createConnection.id}" - } - ] - } - ], - "reconnectionSteps": [ - { - "step": 1, - "type": "mutation", - "name": "resetConnection", - "arguments": [ - { - "name": "id", - "value": "{connection.id}" - } - ] - }, - { - "step": 2, - "type": "mutation", - "name": "updateConnection", - "arguments": [ - { - "name": "id", - "value": "{connection.id}" - }, - { - "name": "formattedData", - "value": null, - "properties": [ - { - "name": "consumerKey", - "value": "{fields.consumerKey}" - }, - { - "name": "consumerSecret", - "value": "{fields.consumerSecret}" - } - ] - } - ] - }, - { - "step": 3, - "type": "mutation", - "name": "createAuthData", - "arguments": [ - { - "name": "id", - "value": "{connection.id}" - } - ] - }, - { - "step": 4, - "type": "openWithPopup", - "name": "openAuthPopup", - "arguments": [ - { - "name": "url", - "value": "{createAuthData.url}" - } - ] - }, - { - "step": 5, - "type": "mutation", - "name": "updateConnection", - "arguments": [ - { - "name": "id", - "value": "{connection.id}" - }, - { - "name": "formattedData", - "value": null, - "properties": [ - { - "name": "oauthVerifier", - "value": "{openAuthPopup.code}" - } - ] - } - ] - }, - { - "step": 6, - "type": "mutation", - "name": "verifyConnection", - "arguments": [ - { - "name": "id", - "value": "{connection.id}" - } - ] - } - ] -}