From ccba7fc9db6fe2878d8d87da850b4907f514a439 Mon Sep 17 00:00:00 2001 From: GeopJr Date: Sat, 11 Feb 2023 20:08:12 +0000 Subject: [PATCH] =?UTF-8?q?feat:=20=E2=9C=A8=20don't=20depend=20on=20an=20?= =?UTF-8?q?external=20service=20for=20urn:ietf:wg:oauth:2.0:oob=20(#9602)?= =?UTF-8?q?=20Co-authored-by:=20GeopJr=20=20Co-committed-?= =?UTF-8?q?by:=20GeopJr=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- locales/en-US.yml | 1 + .../src/server/api/mastodon/endpoints/auth.ts | 5 +---- packages/client/src/pages/auth.vue | 15 +++++++++++++-- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/locales/en-US.yml b/locales/en-US.yml index f43f01fb7..afcb0e24a 100644 --- a/locales/en-US.yml +++ b/locales/en-US.yml @@ -1294,6 +1294,7 @@ _auth: pleaseGoBack: "Please go back to the application" callback: "Returning to the application" denied: "Access denied" + copyAsk: "Please paste the following authorization code to the application" _antennaSources: all: "All posts" homeTimeline: "Posts from followed users" diff --git a/packages/backend/src/server/api/mastodon/endpoints/auth.ts b/packages/backend/src/server/api/mastodon/endpoints/auth.ts index 46b013f3f..6ada2e95a 100644 --- a/packages/backend/src/server/api/mastodon/endpoints/auth.ts +++ b/packages/backend/src/server/api/mastodon/endpoints/auth.ts @@ -58,10 +58,7 @@ export function apiAuthMastodon(router: Router): void { } const scopeArr = Array.from(pushScope); - let red = body.redirect_uris; - if (red === "urn:ietf:wg:oauth:2.0:oob") { - red = "https://thedesk.top/hello.html"; - } + const red = body.redirect_uris; const appData = await client.registerApp(body.client_name, { scopes: scopeArr, redirect_uris: red, diff --git a/packages/client/src/pages/auth.vue b/packages/client/src/pages/auth.vue index 9fc04d4f4..c3f580160 100644 --- a/packages/client/src/pages/auth.vue +++ b/packages/client/src/pages/auth.vue @@ -16,7 +16,11 @@

{{ session.app.isAuthorized ? i18n.t('already-authorized') : i18n.ts.allowed }}

-

{{ i18n.ts._auth.callback }}

+

{{ i18n.ts._auth.callback }}

+ + + +

{{ i18n.ts._auth.pleaseGoBack }}

@@ -32,6 +36,7 @@ import { defineComponent } from 'vue'; import XForm from './auth.form.vue'; import MkSignin from '@/components/MkSignin.vue'; +import MkKeyValue from '@/components/MkKeyValue.vue'; import * as os from '@/os'; import { login } from '@/account'; import { i18n } from '@/i18n'; @@ -40,6 +45,7 @@ export default defineComponent({ components: { XForm, MkSignin, + MkKeyValue }, props: ['token'], data() { @@ -48,6 +54,7 @@ export default defineComponent({ session: null, fetching: true, i18n, + auth_code: null }; }, mounted() { @@ -82,7 +89,11 @@ export default defineComponent({ 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'); - location.href = `${this.session.app.callbackUrl}?token=${this.session.token}&code=${this.session.token}&state=${getUrlParams().state || ''}`; + if (this.session.app.callbackUrl === "urn:ietf:wg:oauth:2.0:oob") { + this.auth_code = this.session.token; + } else { + location.href = `${this.session.app.callbackUrl}?token=${this.session.token}&code=${this.session.token}&state=${getUrlParams().state || ''}`; + } } }, onLogin(res) { login(res.i);