Skip to content

Commit fa532f8

Browse files
committed
feat: instagram standalone refresh token
1 parent 12ba2e9 commit fa532f8

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

libraries/nestjs-libraries/src/integrations/social/instagram.standalone.provider.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,26 @@ export class InstagramStandaloneProvider
2828
];
2929

3030
async refreshToken(refresh_token: string): Promise<AuthTokenDetails> {
31+
const { access_token } = await (
32+
await this.fetch(
33+
`https://graph.instagram.com/refresh_access_token?grant_type=ig_refresh_token&access_token=${refresh_token}`
34+
)
35+
).json();
36+
37+
const { user_id, name, username, profile_picture_url } = await (
38+
await this.fetch(
39+
`https://graph.instagram.com/v21.0/me?fields=user_id,username,name,profile_picture_url&access_token=${access_token}`
40+
)
41+
).json();
42+
3143
return {
32-
refreshToken: '',
33-
expiresIn: 0,
34-
accessToken: '',
35-
id: '',
36-
name: '',
37-
picture: '',
38-
username: '',
44+
id: user_id,
45+
name,
46+
accessToken: access_token,
47+
refreshToken: access_token,
48+
expiresIn: dayjs().add(59, 'days').unix() - dayjs().unix(),
49+
picture: profile_picture_url,
50+
username,
3951
};
4052
}
4153

0 commit comments

Comments
 (0)