From 30cc0a9b18492ad0fa10668caf3b7f990878af78 Mon Sep 17 00:00:00 2001 From: Mar0xy Date: Sun, 24 Sep 2023 23:01:46 +0200 Subject: [PATCH] fix: oauth headers --- .../api/mastodon/MastodonApiServerService.ts | 2 +- .../src/server/oauth/OAuth2ProviderService.ts | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/backend/src/server/api/mastodon/MastodonApiServerService.ts b/packages/backend/src/server/api/mastodon/MastodonApiServerService.ts index f107c14d8..6ab1d1559 100644 --- a/packages/backend/src/server/api/mastodon/MastodonApiServerService.ts +++ b/packages/backend/src/server/api/mastodon/MastodonApiServerService.ts @@ -48,7 +48,7 @@ export class MastodonApiServerService { fastify.addContentTypeParser(['application/x-www-form-urlencoded'], { parseAs: 'string' }, (req, body, done) => { const dataObj: any = {}; const parsedData = new URLSearchParams(body as string); - for (let pair of parsedData.entries()) { + for (const pair of parsedData.entries()) { dataObj[pair[0]] = pair[1]; } done(null, dataObj); diff --git a/packages/backend/src/server/oauth/OAuth2ProviderService.ts b/packages/backend/src/server/oauth/OAuth2ProviderService.ts index 973f9c1eb..1cac987f0 100644 --- a/packages/backend/src/server/oauth/OAuth2ProviderService.ts +++ b/packages/backend/src/server/oauth/OAuth2ProviderService.ts @@ -37,6 +37,20 @@ export class OAuth2ProviderService { }); }); */ + fastify.addHook('onRequest', (request, reply, done) => { + reply.header('Access-Control-Allow-Origin', '*'); + done(); + }); + + fastify.addContentTypeParser(['application/x-www-form-urlencoded'], { parseAs: 'string' }, (req, body, done) => { + const dataObj: any = {}; + const parsedData = new URLSearchParams(body as string); + for (const pair of parsedData.entries()) { + dataObj[pair[0]] = pair[1]; + } + done(null, dataObj); + }); + fastify.get('/oauth/authorize', async (request, reply) => { const query: any = request.query; let param = "mastodon=true";