Skip to content

Commit cf9a2e6

Browse files
author
Nevo David
committed
feat: fixes
1 parent d87b642 commit cf9a2e6

File tree

2 files changed

+19
-37
lines changed

2 files changed

+19
-37
lines changed

libraries/nestjs-libraries/src/integrations/social/discord.provider.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,11 @@ export class DiscordProvider extends SocialAbstract implements SocialProvider {
6969
codeVerifier: string;
7070
refresh?: string;
7171
}) {
72-
const [newCode, guild] = params.code.split(':');
73-
const { access_token, expires_in, refresh_token, scope } = await (
72+
const { access_token, expires_in, refresh_token, scope, guild } = await (
7473
await this.fetch('https://discord.com/api/oauth2/token', {
7574
method: 'POST',
7675
body: new URLSearchParams({
77-
code: newCode,
76+
code: params.code,
7877
grant_type: 'authorization_code',
7978
redirect_uri: `${process.env.FRONTEND_URL}/integrations/social/discord`,
8079
}),
@@ -100,7 +99,7 @@ export class DiscordProvider extends SocialAbstract implements SocialProvider {
10099
).json();
101100

102101
return {
103-
id: guild,
102+
id: guild.id,
104103
name: application.name,
105104
accessToken: access_token,
106105
refreshToken: refresh_token,

libraries/nestjs-libraries/src/integrations/social/slack.provider.ts

Lines changed: 16 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -13,40 +13,21 @@ export class SlackProvider extends SocialAbstract implements SocialProvider {
1313
identifier = 'slack';
1414
name = 'Slack';
1515
isBetweenSteps = false;
16-
scopes = ['identify', 'guilds'];
16+
scopes = [
17+
'channels:read',
18+
'chat:write',
19+
'users:read',
20+
'groups:read',
21+
'channels:join',
22+
'chat:write.customize',
23+
];
1724
async refreshToken(refreshToken: string): Promise<AuthTokenDetails> {
18-
const { access_token, expires_in, refresh_token } = await (
19-
await this.fetch('https://discord.com/api/oauth2/token', {
20-
method: 'POST',
21-
body: new URLSearchParams({
22-
refresh_token: refreshToken,
23-
grant_type: 'refresh_token',
24-
}),
25-
headers: {
26-
'Content-Type': 'application/x-www-form-urlencoded',
27-
Authorization: `Basic ${Buffer.from(
28-
process.env.DISCORD_CLIENT_ID +
29-
':' +
30-
process.env.DISCORD_CLIENT_SECRET
31-
).toString('base64')}`,
32-
},
33-
})
34-
).json();
35-
36-
const { application } = await (
37-
await fetch('https://discord.com/api/oauth2/@me', {
38-
headers: {
39-
Authorization: `Bearer ${access_token}`,
40-
},
41-
})
42-
).json();
43-
4425
return {
45-
refreshToken: refresh_token,
46-
expiresIn: expires_in,
47-
accessToken: access_token,
26+
refreshToken: '',
27+
expiresIn: 1000000,
28+
accessToken: '',
4829
id: '',
49-
name: application.name,
30+
name: '',
5031
picture: '',
5132
username: '',
5233
};
@@ -76,7 +57,7 @@ export class SlackProvider extends SocialAbstract implements SocialProvider {
7657
codeVerifier: string;
7758
refresh?: string;
7859
}) {
79-
const { access_token, team, bot_user_id, authed_user, ...all } = await (
60+
const { access_token, team, bot_user_id, scope } = await (
8061
await this.fetch(`https://slack.com/api/oauth.v2.access`, {
8162
method: 'POST',
8263
headers: {
@@ -97,6 +78,8 @@ export class SlackProvider extends SocialAbstract implements SocialProvider {
9778
})
9879
).json();
9980

81+
this.checkScopes(this.scopes, scope.split(','));
82+
10083
const { user } = await (
10184
await fetch(`https://slack.com/api/users.info?user=${bot_user_id}`, {
10285
method: 'GET',
@@ -112,7 +95,7 @@ export class SlackProvider extends SocialAbstract implements SocialProvider {
11295
accessToken: access_token,
11396
refreshToken: 'null',
11497
expiresIn: dayjs().add(100, 'years').unix() - dayjs().unix(),
115-
picture: user.profile.image_48,
98+
picture: user.profile.image_original,
11699
username: user.name,
117100
};
118101
}

0 commit comments

Comments
 (0)