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,
redirect_uri: callbackUrl,
response_type: 'code',
permissions: '2146958591',
scope: scopes.join(' '),
});

View File

@@ -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}'
}
]
}

View File

@@ -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,
});
};

View File

@@ -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;

View File

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