From 119650048e3ec68e275a5572aed45b77a73e4600 Mon Sep 17 00:00:00 2001 From: Ali BARIN Date: Sun, 9 Oct 2022 14:46:51 +0200 Subject: [PATCH] chore: delete unused discord app --- .../src/apps/discord/assets/favicon.svg | 4 - .../src/apps/discord/authentication.ts | 99 -------- packages/backend/src/apps/discord/index.d.ts | 0 packages/backend/src/apps/discord/index.ts | 15 -- packages/backend/src/apps/discord/info.json | 219 ------------------ 5 files changed, 337 deletions(-) delete mode 100644 packages/backend/src/apps/discord/assets/favicon.svg delete mode 100644 packages/backend/src/apps/discord/authentication.ts delete mode 100644 packages/backend/src/apps/discord/index.d.ts delete mode 100644 packages/backend/src/apps/discord/index.ts delete mode 100644 packages/backend/src/apps/discord/info.json diff --git a/packages/backend/src/apps/discord/assets/favicon.svg b/packages/backend/src/apps/discord/assets/favicon.svg deleted file mode 100644 index 0483a9d3..00000000 --- a/packages/backend/src/apps/discord/assets/favicon.svg +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/packages/backend/src/apps/discord/authentication.ts b/packages/backend/src/apps/discord/authentication.ts deleted file mode 100644 index ebcc8239..00000000 --- a/packages/backend/src/apps/discord/authentication.ts +++ /dev/null @@ -1,99 +0,0 @@ -import type { - IAuthentication, - IApp, - IField, - IJSONObject, -} from '@automatisch/types'; -import { URLSearchParams } from 'url'; -import axios, { AxiosInstance } from 'axios'; - -export default class Authentication implements IAuthentication { - appData: IApp; - connectionData: IJSONObject; - client: AxiosInstance = axios.create({ - baseURL: 'https://discord.com/api/', - }); - - scope: string[] = ['identify', 'email']; - - constructor(appData: IApp, connectionData: IJSONObject) { - this.appData = appData; - this.connectionData = connectionData; - } - - get oauthRedirectUrl() { - return this.appData.fields.find( - (field: IField) => field.key == 'oAuthRedirectUrl' - ).value; - } - - async createAuthData() { - const searchParams = new URLSearchParams({ - client_id: this.connectionData.consumerKey as string, - redirect_uri: this.oauthRedirectUrl, - response_type: 'code', - scope: this.scope.join(' '), - }); - - const url = `https://discord.com/api/oauth2/authorize?${searchParams.toString()}`; - - return { url }; - } - - async verifyCredentials() { - const params = new URLSearchParams({ - client_id: this.connectionData.consumerKey as string, - redirect_uri: this.oauthRedirectUrl, - response_type: 'code', - scope: this.scope.join(' '), - client_secret: this.connectionData.consumerSecret as string, - code: this.connectionData.oauthVerifier as string, - grant_type: 'authorization_code', - }); - const { data: verifiedCredentials } = await this.client.post( - '/oauth2/token', - params.toString() - ); - - const { - access_token: accessToken, - refresh_token: refreshToken, - expires_in: expiresIn, - scope: scope, - token_type: tokenType, - } = verifiedCredentials; - - const { data: user } = await this.client.get('/users/@me', { - headers: { - Authorization: `${tokenType} ${accessToken}`, - }, - }); - - return { - consumerKey: this.connectionData.consumerKey, - consumerSecret: this.connectionData.consumerSecret, - accessToken, - refreshToken, - expiresIn, - scope, - tokenType, - userId: user.id, - screenName: user.username, - email: user.email, - }; - } - - async isStillVerified() { - try { - await this.client.get('/users/@me', { - headers: { - Authorization: `${this.connectionData.tokenType} ${this.connectionData.accessToken}`, - }, - }); - - return true; - } catch { - return false; - } - } -} diff --git a/packages/backend/src/apps/discord/index.d.ts b/packages/backend/src/apps/discord/index.d.ts deleted file mode 100644 index e69de29b..00000000 diff --git a/packages/backend/src/apps/discord/index.ts b/packages/backend/src/apps/discord/index.ts deleted file mode 100644 index 80de7f88..00000000 --- a/packages/backend/src/apps/discord/index.ts +++ /dev/null @@ -1,15 +0,0 @@ -import Authentication from './authentication'; -import { - IService, - IAuthentication, - IApp, - IJSONObject, -} from '@automatisch/types'; - -export default class Discord implements IService { - authenticationClient: IAuthentication; - - constructor(appData: IApp, connectionData: IJSONObject) { - this.authenticationClient = new Authentication(appData, connectionData); - } -} diff --git a/packages/backend/src/apps/discord/info.json b/packages/backend/src/apps/discord/info.json deleted file mode 100644 index fbcf9ac2..00000000 --- a/packages/backend/src/apps/discord/info.json +++ /dev/null @@ -1,219 +0,0 @@ -{ - "name": "Discord", - "key": "discord", - "iconUrl": "{BASE_URL}/apps/discord/assets/favicon.svg", - "docUrl": "https://automatisch.io/docs/discord", - "primaryColor": "5865f2", - "supportsConnections": true, - "fields": [ - { - "key": "oAuthRedirectUrl", - "label": "OAuth Redirect URL", - "type": "string", - "required": true, - "readOnly": true, - "value": "{WEB_APP_URL}/app/discord/connections/add", - "placeholder": null, - "description": "When asked to input an OAuth callback or redirect URL in Discord OAuth, enter the URL above.", - "docUrl": "https://automatisch.io/docs/discord#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/discord#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/discord#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}" - } - ] - } - ] -}