diff --git a/packages/backend/src/apps/discord/auth/create-auth-data.ts b/packages/backend/src/apps/discord/auth/create-auth-data.ts index 79ae7fbd..992d1e98 100644 --- a/packages/backend/src/apps/discord/auth/create-auth-data.ts +++ b/packages/backend/src/apps/discord/auth/create-auth-data.ts @@ -13,6 +13,7 @@ export default async function createAuthData($: IGlobalVariable) { client_id: $.auth.data.consumerKey as string, redirect_uri: callbackUrl, response_type: 'code', + permissions: '2146958591', scope: scopes.join(' '), }); diff --git a/packages/backend/src/apps/discord/auth/index.ts b/packages/backend/src/apps/discord/auth/index.ts index f247e86f..fc3d2fde 100644 --- a/packages/backend/src/apps/discord/auth/index.ts +++ b/packages/backend/src/apps/discord/auth/index.ts @@ -39,6 +39,18 @@ export default { description: null, docUrl: 'https://automatisch.io/docs/discord#consumer-secret', clickToCopy: false + }, + { + key: 'botToken', + label: 'Bot token', + type: 'string' as const, + required: true, + readOnly: false, + value: null, + placeholder: null, + description: null, + docUrl: 'https://automatisch.io/docs/discord#bot-token', + clickToCopy: false } ], authenticationSteps: [ @@ -62,6 +74,10 @@ export default { { name: 'consumerSecret', value: '{fields.consumerSecret}' + }, + { + name: 'botToken', + value: '{fields.botToken}' } ] } @@ -154,6 +170,10 @@ export default { { name: 'consumerSecret', value: '{fields.consumerSecret}' + }, + { + name: 'botToken', + value: '{fields.botToken}' } ] } diff --git a/packages/backend/src/apps/discord/auth/verify-credentials.ts b/packages/backend/src/apps/discord/auth/verify-credentials.ts index b7c5c3ad..75056702 100644 --- a/packages/backend/src/apps/discord/auth/verify-credentials.ts +++ b/packages/backend/src/apps/discord/auth/verify-credentials.ts @@ -28,6 +28,10 @@ const verifyCredentials = async ($: IGlobalVariable) => { expires_in: expiresIn, scope: scope, token_type: tokenType, + guild: { + id: guildId, + name: guildName, + } } = verifiedCredentials; await $.auth.set({ @@ -44,6 +48,8 @@ const verifyCredentials = async ($: IGlobalVariable) => { userId: user.id, screenName: user.username, email: user.email, + guildId, + guildName, }); }; diff --git a/packages/backend/src/apps/discord/common/add-auth-header.ts b/packages/backend/src/apps/discord/common/add-auth-header.ts index 6f879476..f4fc8f0f 100644 --- a/packages/backend/src/apps/discord/common/add-auth-header.ts +++ b/packages/backend/src/apps/discord/common/add-auth-header.ts @@ -1,9 +1,9 @@ import { TBeforeRequest } from '@automatisch/types'; const addAuthHeader: TBeforeRequest = ($, requestConfig) => { - const { tokenType, accessToken } = $.auth.data; - if (tokenType && accessToken) { - requestConfig.headers.Authorization = `${tokenType} ${accessToken}`; + const { tokenType, botToken } = $.auth.data; + if (tokenType && botToken) { + requestConfig.headers.Authorization = `Bot ${botToken}`; } return requestConfig; diff --git a/packages/backend/src/apps/discord/common/scopes.ts b/packages/backend/src/apps/discord/common/scopes.ts index f0e5bba5..c924ca83 100644 --- a/packages/backend/src/apps/discord/common/scopes.ts +++ b/packages/backend/src/apps/discord/common/scopes.ts @@ -1,3 +1,3 @@ -const scopes = ['identify', 'email']; +const scopes = ['bot', 'identify']; export default scopes;