feat(discord): use bot auth instead of user

This commit is contained in:
Ali BARIN
2022-10-30 22:25:11 +01:00
parent 798769d5ae
commit c2b020fc94
5 changed files with 31 additions and 4 deletions

View File

@@ -13,6 +13,7 @@ export default async function createAuthData($: IGlobalVariable) {
client_id: $.auth.data.consumerKey as string, client_id: $.auth.data.consumerKey as string,
redirect_uri: callbackUrl, redirect_uri: callbackUrl,
response_type: 'code', response_type: 'code',
permissions: '2146958591',
scope: scopes.join(' '), scope: scopes.join(' '),
}); });

View File

@@ -39,6 +39,18 @@ export default {
description: null, description: null,
docUrl: 'https://automatisch.io/docs/discord#consumer-secret', docUrl: 'https://automatisch.io/docs/discord#consumer-secret',
clickToCopy: false 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: [ authenticationSteps: [
@@ -62,6 +74,10 @@ export default {
{ {
name: 'consumerSecret', name: 'consumerSecret',
value: '{fields.consumerSecret}' value: '{fields.consumerSecret}'
},
{
name: 'botToken',
value: '{fields.botToken}'
} }
] ]
} }
@@ -154,6 +170,10 @@ export default {
{ {
name: 'consumerSecret', name: 'consumerSecret',
value: '{fields.consumerSecret}' value: '{fields.consumerSecret}'
},
{
name: 'botToken',
value: '{fields.botToken}'
} }
] ]
} }

View File

@@ -28,6 +28,10 @@ const verifyCredentials = async ($: IGlobalVariable) => {
expires_in: expiresIn, expires_in: expiresIn,
scope: scope, scope: scope,
token_type: tokenType, token_type: tokenType,
guild: {
id: guildId,
name: guildName,
}
} = verifiedCredentials; } = verifiedCredentials;
await $.auth.set({ await $.auth.set({
@@ -44,6 +48,8 @@ const verifyCredentials = async ($: IGlobalVariable) => {
userId: user.id, userId: user.id,
screenName: user.username, screenName: user.username,
email: user.email, email: user.email,
guildId,
guildName,
}); });
}; };

View File

@@ -1,9 +1,9 @@
import { TBeforeRequest } from '@automatisch/types'; import { TBeforeRequest } from '@automatisch/types';
const addAuthHeader: TBeforeRequest = ($, requestConfig) => { const addAuthHeader: TBeforeRequest = ($, requestConfig) => {
const { tokenType, accessToken } = $.auth.data; const { tokenType, botToken } = $.auth.data;
if (tokenType && accessToken) { if (tokenType && botToken) {
requestConfig.headers.Authorization = `${tokenType} ${accessToken}`; requestConfig.headers.Authorization = `Bot ${botToken}`;
} }
return requestConfig; return requestConfig;

View File

@@ -1,3 +1,3 @@
const scopes = ['identify', 'email']; const scopes = ['bot', 'identify'];
export default scopes; export default scopes;