diff --git a/packages/backend/src/apps/deepl/auth/index.ts b/packages/backend/src/apps/deepl/auth/index.ts index 29b49a0c..ed02f1bc 100644 --- a/packages/backend/src/apps/deepl/auth/index.ts +++ b/packages/backend/src/apps/deepl/auth/index.ts @@ -27,42 +27,6 @@ export default { clickToCopy: false, }, ], - authenticationSteps: [ - { - type: 'mutation' as const, - name: 'createConnection', - arguments: [ - { - name: 'key', - value: '{key}', - }, - { - name: 'formattedData', - value: null, - properties: [ - { - name: 'screenName', - value: '{fields.screenName}', - }, - { - name: 'authenticationKey', - value: '{fields.authenticationKey}', - }, - ], - }, - ], - }, - { - type: 'mutation' as const, - name: 'verifyConnection', - arguments: [ - { - name: 'id', - value: '{createConnection.id}', - }, - ], - }, - ], verifyCredentials, isStillVerified, diff --git a/packages/backend/src/apps/discord/auth/index.ts b/packages/backend/src/apps/discord/auth/index.ts index 52be17b0..8466e1f0 100644 --- a/packages/backend/src/apps/discord/auth/index.ts +++ b/packages/backend/src/apps/discord/auth/index.ts @@ -3,6 +3,7 @@ import verifyCredentials from './verify-credentials'; import isStillVerified from './is-still-verified'; export default { + generateAuthUrl: true, fields: [ { key: 'oAuthRedirectUrl', @@ -54,86 +55,6 @@ export default { clickToCopy: false, }, ], - authenticationSteps: [ - { - type: 'mutation' as const, - name: 'createConnection', - arguments: [ - { - name: 'key', - value: '{key}', - }, - { - name: 'formattedData', - value: null, - properties: [ - { - name: 'consumerKey', - value: '{fields.consumerKey}', - }, - { - name: 'consumerSecret', - value: '{fields.consumerSecret}', - }, - { - name: 'botToken', - value: '{fields.botToken}', - }, - ], - }, - ], - }, - { - type: 'mutation' as const, - name: 'createAuthData', - arguments: [ - { - name: 'id', - value: '{createConnection.id}', - }, - ], - }, - { - type: 'openWithPopup' as const, - name: 'openAuthPopup', - arguments: [ - { - name: 'url', - value: '{createAuthData.url}', - }, - ], - }, - { - type: 'mutation' as const, - name: 'updateConnection', - arguments: [ - { - name: 'id', - value: '{createConnection.id}', - }, - { - name: 'formattedData', - value: null, - properties: [ - { - name: 'oauthVerifier', - value: '{openAuthPopup.code}', - }, - ], - }, - ], - }, - { - type: 'mutation' as const, - name: 'verifyConnection', - arguments: [ - { - name: 'id', - value: '{createConnection.id}', - }, - ], - }, - ], createAuthData, verifyCredentials, diff --git a/packages/backend/src/apps/discord/auth/verify-credentials.ts b/packages/backend/src/apps/discord/auth/verify-credentials.ts index 491f4e84..13d012e6 100644 --- a/packages/backend/src/apps/discord/auth/verify-credentials.ts +++ b/packages/backend/src/apps/discord/auth/verify-credentials.ts @@ -14,7 +14,7 @@ const verifyCredentials = async ($: IGlobalVariable) => { response_type: 'code', scope: scopes.join(' '), client_secret: $.auth.data.consumerSecret as string, - code: $.auth.data.oauthVerifier as string, + code: $.auth.data.code as string, grant_type: 'authorization_code', }); const { data: verifiedCredentials } = await $.http.post( diff --git a/packages/backend/src/apps/flickr/auth/index.ts b/packages/backend/src/apps/flickr/auth/index.ts index ecdef330..1c3c8b2f 100644 --- a/packages/backend/src/apps/flickr/auth/index.ts +++ b/packages/backend/src/apps/flickr/auth/index.ts @@ -3,6 +3,7 @@ import verifyCredentials from './verify-credentials'; import isStillVerified from './is-still-verified'; export default { + generateAuthUrl: true, fields: [ { key: 'oAuthRedirectUrl', @@ -42,82 +43,6 @@ export default { clickToCopy: false, }, ], - authenticationSteps: [ - { - type: 'mutation' as const, - name: 'createConnection', - arguments: [ - { - name: 'key', - value: '{key}', - }, - { - name: 'formattedData', - value: null, - properties: [ - { - name: 'consumerKey', - value: '{fields.consumerKey}', - }, - { - name: 'consumerSecret', - value: '{fields.consumerSecret}', - }, - ], - }, - ], - }, - { - type: 'mutation' as const, - name: 'createAuthData', - arguments: [ - { - name: 'id', - value: '{createConnection.id}', - }, - ], - }, - { - type: 'openWithPopup' as const, - name: 'openAuthPopup', - arguments: [ - { - name: 'url', - value: '{createAuthData.url}', - }, - ], - }, - { - type: 'mutation' as const, - name: 'updateConnection', - arguments: [ - { - name: 'id', - value: '{createConnection.id}', - }, - { - name: 'formattedData', - value: null, - properties: [ - { - name: 'oauthVerifier', - value: '{openAuthPopup.oauth_verifier}', - }, - ], - }, - ], - }, - { - type: 'mutation' as const, - name: 'verifyConnection', - arguments: [ - { - name: 'id', - value: '{createConnection.id}', - }, - ], - }, - ], createAuthData, verifyCredentials, diff --git a/packages/backend/src/apps/flickr/auth/verify-credentials.ts b/packages/backend/src/apps/flickr/auth/verify-credentials.ts index 4539dc26..4a42af8f 100644 --- a/packages/backend/src/apps/flickr/auth/verify-credentials.ts +++ b/packages/backend/src/apps/flickr/auth/verify-credentials.ts @@ -3,7 +3,7 @@ import { URLSearchParams } from 'url'; const verifyCredentials = async ($: IGlobalVariable) => { const response = await $.http.post( - `/oauth/access_token?oauth_verifier=${$.auth.data.oauthVerifier}&oauth_token=${$.auth.data.accessToken}`, + `/oauth/access_token?oauth_verifier=${$.auth.data.oauth_verifier}&oauth_token=${$.auth.data.accessToken}`, null ); diff --git a/packages/backend/src/apps/github/auth/index.ts b/packages/backend/src/apps/github/auth/index.ts index 5f6a9f21..d95dbd2e 100644 --- a/packages/backend/src/apps/github/auth/index.ts +++ b/packages/backend/src/apps/github/auth/index.ts @@ -3,6 +3,7 @@ import verifyCredentials from './verify-credentials'; import isStillVerified from './is-still-verified'; export default { + generateAuthUrl: true, fields: [ { key: 'oAuthRedirectUrl', @@ -42,82 +43,6 @@ export default { clickToCopy: false, }, ], - authenticationSteps: [ - { - type: 'mutation' as const, - name: 'createConnection', - arguments: [ - { - name: 'key', - value: '{key}', - }, - { - name: 'formattedData', - value: null, - properties: [ - { - name: 'consumerKey', - value: '{fields.consumerKey}', - }, - { - name: 'consumerSecret', - value: '{fields.consumerSecret}', - }, - ], - }, - ], - }, - { - type: 'mutation' as const, - name: 'createAuthData', - arguments: [ - { - name: 'id', - value: '{createConnection.id}', - }, - ], - }, - { - type: 'openWithPopup' as const, - name: 'openAuthPopup', - arguments: [ - { - name: 'url', - value: '{createAuthData.url}', - }, - ], - }, - { - type: 'mutation' as const, - name: 'updateConnection', - arguments: [ - { - name: 'id', - value: '{createConnection.id}', - }, - { - name: 'formattedData', - value: null, - properties: [ - { - name: 'oauthVerifier', - value: '{openAuthPopup.code}', - }, - ], - }, - ], - }, - { - type: 'mutation' as const, - name: 'verifyConnection', - arguments: [ - { - name: 'id', - value: '{createConnection.id}', - }, - ], - }, - ], createAuthData, verifyCredentials, diff --git a/packages/backend/src/apps/github/auth/verify-credentials.ts b/packages/backend/src/apps/github/auth/verify-credentials.ts index 53950337..d6407ed0 100644 --- a/packages/backend/src/apps/github/auth/verify-credentials.ts +++ b/packages/backend/src/apps/github/auth/verify-credentials.ts @@ -7,7 +7,7 @@ const verifyCredentials = async ($: IGlobalVariable) => { { client_id: $.auth.data.consumerKey, client_secret: $.auth.data.consumerSecret, - code: $.auth.data.oauthVerifier, + code: $.auth.data.code, }, { headers: { diff --git a/packages/backend/src/apps/salesforce/auth/index.ts b/packages/backend/src/apps/salesforce/auth/index.ts index fdbd6cb8..5fdd460c 100644 --- a/packages/backend/src/apps/salesforce/auth/index.ts +++ b/packages/backend/src/apps/salesforce/auth/index.ts @@ -3,6 +3,7 @@ import verifyCredentials from './verify-credentials'; import isStillVerified from './is-still-verified'; export default { + generateAuthUrl: true, fields: [ { key: 'oAuthRedirectUrl', @@ -60,91 +61,6 @@ export default { clickToCopy: false, }, ], - authenticationSteps: [ - { - step: 1, - type: 'mutation' as const, - name: 'createConnection', - arguments: [ - { - name: 'key', - value: '{key}', - }, - { - name: 'formattedData', - value: null, - properties: [ - { - name: 'oauth2Url', - value: '{fields.oauth2Url}', - }, - { - name: 'consumerKey', - value: '{fields.consumerKey}', - }, - { - name: 'consumerSecret', - value: '{fields.consumerSecret}', - }, - ], - }, - ], - }, - { - step: 2, - type: 'mutation' as const, - name: 'createAuthData', - arguments: [ - { - name: 'id', - value: '{createConnection.id}', - }, - ], - }, - { - step: 3, - type: 'openWithPopup' as const, - name: 'openAuthPopup', - arguments: [ - { - name: 'url', - value: '{createAuthData.url}', - }, - ], - }, - { - step: 4, - type: 'mutation' as const, - name: 'updateConnection', - arguments: [ - { - name: 'id', - value: '{createConnection.id}', - }, - { - name: 'formattedData', - value: null, - properties: [ - { - name: 'code', - value: '{openAuthPopup.code}', - }, - ], - }, - ], - }, - { - step: 5, - type: 'mutation' as const, - name: 'verifyConnection', - arguments: [ - { - name: 'id', - value: '{createConnection.id}', - }, - ], - }, - ], createAuthData, verifyCredentials, diff --git a/packages/backend/src/apps/slack/auth/index.ts b/packages/backend/src/apps/slack/auth/index.ts index d6d95165..a30ff8a4 100644 --- a/packages/backend/src/apps/slack/auth/index.ts +++ b/packages/backend/src/apps/slack/auth/index.ts @@ -3,6 +3,7 @@ import verifyCredentials from './verify-credentials'; import isStillVerified from './is-still-verified'; export default { + generateAuthUrl: true, fields: [ { key: 'oAuthRedirectUrl', @@ -39,86 +40,6 @@ export default { clickToCopy: false, }, ], - authenticationSteps: [ - { - type: 'mutation' as const, - name: 'createConnection', - arguments: [ - { - name: 'key', - value: '{key}', - }, - { - name: 'formattedData', - value: null, - properties: [ - { - name: 'consumerKey', - value: '{fields.consumerKey}', - }, - { - name: 'consumerSecret', - value: '{fields.consumerSecret}', - }, - ], - }, - ], - }, - { - type: 'mutation' as const, - name: 'createAuthData', - arguments: [ - { - name: 'id', - value: '{createConnection.id}', - }, - ], - }, - { - type: 'openWithPopup' as const, - name: 'openAuthPopup', - arguments: [ - { - name: 'url', - value: '{createAuthData.url}', - }, - ], - }, - { - type: 'mutation' as const, - name: 'updateConnection', - arguments: [ - { - name: 'id', - value: '{createConnection.id}', - }, - { - name: 'formattedData', - value: null, - properties: [ - { - name: 'code', - value: '{openAuthPopup.code}', - }, - { - name: 'state', - value: '{openAuthPopup.state}', - }, - ], - }, - ], - }, - { - type: 'mutation' as const, - name: 'verifyConnection', - arguments: [ - { - name: 'id', - value: '{createConnection.id}', - }, - ], - }, - ], createAuthData, verifyCredentials, diff --git a/packages/backend/src/apps/smtp/auth/index.ts b/packages/backend/src/apps/smtp/auth/index.ts index 2868abad..369aa411 100644 --- a/packages/backend/src/apps/smtp/auth/index.ts +++ b/packages/backend/src/apps/smtp/auth/index.ts @@ -86,58 +86,6 @@ export default { clickToCopy: false, }, ], - authenticationSteps: [ - { - type: 'mutation' as const, - name: 'createConnection', - arguments: [ - { - name: 'key', - value: '{key}', - }, - { - name: 'formattedData', - value: null, - properties: [ - { - name: 'host', - value: '{fields.host}', - }, - { - name: 'username', - value: '{fields.username}', - }, - { - name: 'password', - value: '{fields.password}', - }, - { - name: 'useTLS', - value: '{fields.useTls}', - }, - { - name: 'port', - value: '{fields.port}', - }, - { - name: 'fromEmail', - value: '{fields.fromEmail}', - }, - ], - }, - ], - }, - { - type: 'mutation' as const, - name: 'verifyConnection', - arguments: [ - { - name: 'id', - value: '{createConnection.id}', - }, - ], - }, - ], verifyCredentials, isStillVerified, }; diff --git a/packages/backend/src/apps/twilio/auth/index.ts b/packages/backend/src/apps/twilio/auth/index.ts index 40e67615..645e8874 100644 --- a/packages/backend/src/apps/twilio/auth/index.ts +++ b/packages/backend/src/apps/twilio/auth/index.ts @@ -27,42 +27,6 @@ export default { clickToCopy: false, }, ], - authenticationSteps: [ - { - type: 'mutation' as const, - name: 'createConnection', - arguments: [ - { - name: 'key', - value: '{key}', - }, - { - name: 'formattedData', - value: null, - properties: [ - { - name: 'accountSid', - value: '{fields.accountSid}', - }, - { - name: 'authToken', - value: '{fields.authToken}', - }, - ], - }, - ], - }, - { - type: 'mutation' as const, - name: 'verifyConnection', - arguments: [ - { - name: 'id', - value: '{createConnection.id}', - }, - ], - }, - ], verifyCredentials, isStillVerified, diff --git a/packages/backend/src/apps/twitter/auth/index.ts b/packages/backend/src/apps/twitter/auth/index.ts index c81e9c96..680dafb5 100644 --- a/packages/backend/src/apps/twitter/auth/index.ts +++ b/packages/backend/src/apps/twitter/auth/index.ts @@ -3,6 +3,7 @@ import verifyCredentials from './verify-credentials'; import isStillVerified from './is-still-verified'; export default { + generateAuthUrl: true, fields: [ { key: 'oAuthRedirectUrl', @@ -39,76 +40,6 @@ export default { clickToCopy: false, }, ], - authenticationSteps: [ - { - type: 'mutation' as const, - name: 'createConnection', - arguments: [ - { - name: 'key', - value: '{key}', - }, - { - name: 'formattedData', - value: null, - properties: [ - { - name: 'consumerKey', - value: '{fields.consumerKey}', - }, - { - name: 'consumerSecret', - value: '{fields.consumerSecret}', - }, - ], - }, - ], - }, - { - type: 'mutation' as const, - name: 'createAuthData', - arguments: [ - { - name: 'id', - value: '{createConnection.id}', - }, - ], - }, - { - type: 'openWithPopup' as const, - name: 'openAuthPopup', - arguments: [ - { - name: 'url', - value: '{createAuthData.url}', - }, - ], - }, - { - type: 'mutation' as const, - name: 'updateConnection', - arguments: [ - { - name: 'id', - value: '{createConnection.id}', - }, - { - name: 'formattedData', - value: '{openAuthPopup.all}', - }, - ], - }, - { - type: 'mutation' as const, - name: 'verifyConnection', - arguments: [ - { - name: 'id', - value: '{createConnection.id}', - }, - ], - }, - ], createAuthData, verifyCredentials, diff --git a/packages/backend/src/helpers/add-authentication-steps.ts b/packages/backend/src/helpers/add-authentication-steps.ts new file mode 100644 index 00000000..fec5e5e9 --- /dev/null +++ b/packages/backend/src/helpers/add-authentication-steps.ts @@ -0,0 +1,101 @@ +import { IApp } from '@automatisch/types'; + +function addAuthenticationSteps(app: IApp): IApp { + if (app.auth.generateAuthUrl) { + app.auth.authenticationSteps = authenticationStepsWithAuthUrl; + } else { + app.auth.authenticationSteps = authenticationStepsWithoutAuthUrl; + } + + return app; +} + +const authenticationStepsWithoutAuthUrl = [ + { + type: 'mutation' as const, + name: 'createConnection', + arguments: [ + { + name: 'key', + value: '{key}', + }, + { + name: 'formattedData', + value: '{fields.all}', + }, + ], + }, + { + type: 'mutation' as const, + name: 'verifyConnection', + arguments: [ + { + name: 'id', + value: '{createConnection.id}', + }, + ], + }, +]; + +const authenticationStepsWithAuthUrl = [ + { + type: 'mutation' as const, + name: 'createConnection', + arguments: [ + { + name: 'key', + value: '{key}', + }, + { + name: 'formattedData', + value: '{fields.all}', + }, + ], + }, + { + type: 'mutation' as const, + name: 'createAuthData', + arguments: [ + { + name: 'id', + value: '{createConnection.id}', + }, + ], + }, + { + type: 'openWithPopup' as const, + name: 'openAuthPopup', + arguments: [ + { + name: 'url', + value: '{createAuthData.url}', + }, + ], + }, + { + type: 'mutation' as const, + name: 'updateConnection', + arguments: [ + { + name: 'id', + value: '{createConnection.id}', + }, + { + name: 'formattedData', + value: '{openAuthPopup.all}', + }, + ], + }, + { + type: 'mutation' as const, + name: 'verifyConnection', + arguments: [ + { + name: 'id', + value: '{createConnection.id}', + }, + ], + }, +]; + +export default addAuthenticationSteps; diff --git a/packages/backend/src/helpers/get-app.ts b/packages/backend/src/helpers/get-app.ts index 2dcea731..52f73894 100644 --- a/packages/backend/src/helpers/get-app.ts +++ b/packages/backend/src/helpers/get-app.ts @@ -8,14 +8,12 @@ import { ITrigger, } from '@automatisch/types'; import { omit, cloneDeep } from 'lodash'; +import addAuthenticationSteps from './add-authentication-steps'; import addReconnectionSteps from './add-reconnection-steps'; type TApps = Record>; const apps = fs - .readdirSync( - path.resolve(__dirname, `../apps/`), - { withFileTypes: true } - ) + .readdirSync(path.resolve(__dirname, `../apps/`), { withFileTypes: true }) .reduce((apps, dirent) => { if (!dirent.isDirectory()) return apps; @@ -36,6 +34,7 @@ const getApp = async (appKey: string, stripFuncs = true) => { let appData: IApp = cloneDeep(await getDefaultExport(appKey)); if (appData.auth) { + appData = addAuthenticationSteps(appData); appData = addReconnectionSteps(appData); } diff --git a/packages/types/index.d.ts b/packages/types/index.d.ts index 6701a7c5..fa169201 100644 --- a/packages/types/index.d.ts +++ b/packages/types/index.d.ts @@ -181,8 +181,9 @@ export interface IAuth { createAuthData?($: IGlobalVariable): Promise; verifyCredentials($: IGlobalVariable): Promise; isStillVerified($: IGlobalVariable): Promise; + generateAuthUrl?: boolean; fields: IField[]; - authenticationSteps: IAuthenticationStep[]; + authenticationSteps?: IAuthenticationStep[]; reconnectionSteps?: IAuthenticationStep[]; }