Skip to content

Commit

Permalink
feat: fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Nevo David committed Oct 3, 2024
1 parent d87b642 commit cf9a2e6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,11 @@ export class DiscordProvider extends SocialAbstract implements SocialProvider {
codeVerifier: string;
refresh?: string;
}) {
const [newCode, guild] = params.code.split(':');
const { access_token, expires_in, refresh_token, scope } = await (
const { access_token, expires_in, refresh_token, scope, guild } = await (
await this.fetch('https://discord.com/api/oauth2/token', {
method: 'POST',
body: new URLSearchParams({
code: newCode,
code: params.code,
grant_type: 'authorization_code',
redirect_uri: `${process.env.FRONTEND_URL}/integrations/social/discord`,
}),
Expand All @@ -100,7 +99,7 @@ export class DiscordProvider extends SocialAbstract implements SocialProvider {
).json();

return {
id: guild,
id: guild.id,
name: application.name,
accessToken: access_token,
refreshToken: refresh_token,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,40 +13,21 @@ export class SlackProvider extends SocialAbstract implements SocialProvider {
identifier = 'slack';
name = 'Slack';
isBetweenSteps = false;
scopes = ['identify', 'guilds'];
scopes = [
'channels:read',
'chat:write',
'users:read',
'groups:read',
'channels:join',
'chat:write.customize',
];
async refreshToken(refreshToken: string): Promise<AuthTokenDetails> {
const { access_token, expires_in, refresh_token } = await (
await this.fetch('https://discord.com/api/oauth2/token', {
method: 'POST',
body: new URLSearchParams({
refresh_token: refreshToken,
grant_type: 'refresh_token',
}),
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
Authorization: `Basic ${Buffer.from(
process.env.DISCORD_CLIENT_ID +
':' +
process.env.DISCORD_CLIENT_SECRET
).toString('base64')}`,
},
})
).json();

const { application } = await (
await fetch('https://discord.com/api/oauth2/@me', {
headers: {
Authorization: `Bearer ${access_token}`,
},
})
).json();

return {
refreshToken: refresh_token,
expiresIn: expires_in,
accessToken: access_token,
refreshToken: '',
expiresIn: 1000000,
accessToken: '',
id: '',
name: application.name,
name: '',
picture: '',
username: '',
};
Expand Down Expand Up @@ -76,7 +57,7 @@ export class SlackProvider extends SocialAbstract implements SocialProvider {
codeVerifier: string;
refresh?: string;
}) {
const { access_token, team, bot_user_id, authed_user, ...all } = await (
const { access_token, team, bot_user_id, scope } = await (
await this.fetch(`https://slack.com/api/oauth.v2.access`, {
method: 'POST',
headers: {
Expand All @@ -97,6 +78,8 @@ export class SlackProvider extends SocialAbstract implements SocialProvider {
})
).json();

this.checkScopes(this.scopes, scope.split(','));

const { user } = await (
await fetch(`https://slack.com/api/users.info?user=${bot_user_id}`, {
method: 'GET',
Expand All @@ -112,7 +95,7 @@ export class SlackProvider extends SocialAbstract implements SocialProvider {
accessToken: access_token,
refreshToken: 'null',
expiresIn: dayjs().add(100, 'years').unix() - dayjs().unix(),
picture: user.profile.image_48,
picture: user.profile.image_original,
username: user.name,
};
}
Expand Down

0 comments on commit cf9a2e6

Please sign in to comment.