From b7ffa05848daa72365f329dcab4bf4bfabf12730 Mon Sep 17 00:00:00 2001 From: Luna Date: Wed, 1 Mar 2023 21:37:49 -0500 Subject: [PATCH] Enable multipart for masto oauth endpoints to fix Ivory --- packages/backend/src/server/index.ts | 15 +++++++++------ packages/client/src/pages/auth.vue | 5 ++--- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/packages/backend/src/server/index.ts b/packages/backend/src/server/index.ts index 6f7dcfd390..92f1c549d5 100644 --- a/packages/backend/src/server/index.ts +++ b/packages/backend/src/server/index.ts @@ -78,6 +78,7 @@ const mastoRouter = new Router(); mastoRouter.use( koaBody({ urlencoded: true, + multipart: true, }), ); @@ -171,6 +172,7 @@ mastoRouter.get("/oauth/authorize", async (ctx) => { mastoRouter.post("/oauth/token", async (ctx) => { const body: any = ctx.request.body || ctx.request.query; console.log('token-request', body) + console.log('token-query', ctx.request.query) let client_id: any = ctx.request.query.client_id; const BASE_URL = `${ctx.request.protocol}://${ctx.request.hostname}`; const generator = (megalodon as any).default; @@ -178,13 +180,14 @@ mastoRouter.post("/oauth/token", async (ctx) => { let m = null; let token = null; if (body.code) { - m = body.code.match(/^([a-zA-Z0-9]{8})([a-zA-Z0-9]{4})([a-zA-Z0-9]{4})([a-zA-Z0-9]{4})([a-zA-Z0-9]{12})/); - if (!m.length) { - ctx.body = { error: "Invalid code" }; - return; - } - token = `${m[1]}-${m[2]}-${m[3]}-${m[4]}-${m[5]}` + //m = body.code.match(/^([a-zA-Z0-9]{8})([a-zA-Z0-9]{4})([a-zA-Z0-9]{4})([a-zA-Z0-9]{4})([a-zA-Z0-9]{12})/); + //if (!m.length) { + // ctx.body = { error: "Invalid code" }; + // return; + //} + //token = `${m[1]}-${m[2]}-${m[3]}-${m[4]}-${m[5]}` console.log(body.code, token) + token = body.code } if (client_id instanceof Array) { client_id = client_id.toString(); diff --git a/packages/client/src/pages/auth.vue b/packages/client/src/pages/auth.vue index b7ea082c64..2b4c67ba78 100644 --- a/packages/client/src/pages/auth.vue +++ b/packages/client/src/pages/auth.vue @@ -88,11 +88,10 @@ export default defineComponent({ const getUrlParams = () => window.location.search.substring(1).split('&').reduce((result, query) => { const [k, v] = query.split('='); result[k] = decodeURI(v); return result; }, {}); const isMastodon = !!getUrlParams().mastodon if (this.session.app.callbackUrl && isMastodon) { - const state = getUrlParams().state - const stateParam = `&state=${state}` + const stateParam = !!getUrlParams().state ? `&state=$(getUrlParams().state)` : ''; const tokenRaw = this.session.token const token = tokenRaw.replaceAll('-', '') - location.href = `${this.session.app.callbackUrl}?code=${token}${stateParam}`; + location.href = `${this.session.app.callbackUrl}?code=${tokenRaw}${stateParam}`; } else if (this.session.app.callbackUrl) { const url = new URL(this.session.app.callbackUrl); if (['javascript:', 'file:', 'data:', 'mailto:', 'tel:'].includes(url.protocol)) throw new Error('invalid url');