mirror of
https://iceshrimp.dev/limepotato/jormungandr-bite.git
synced 2024-11-22 01:47:39 -07:00
[mastodon-client] Fix urlencoded redirect_uris
This commit is contained in:
parent
153c08fae1
commit
3d320c0895
2 changed files with 7 additions and 3 deletions
|
@ -4,6 +4,7 @@ import { convertId, IdType } from "@/misc/convert-id.js";
|
||||||
import { AuthConverter } from "@/server/api/mastodon/converters/auth.js";
|
import { AuthConverter } from "@/server/api/mastodon/converters/auth.js";
|
||||||
import { v4 as uuid } from "uuid";
|
import { v4 as uuid } from "uuid";
|
||||||
import { MastoApiError } from "@/server/api/mastodon/middleware/catch-errors.js";
|
import { MastoApiError } from "@/server/api/mastodon/middleware/catch-errors.js";
|
||||||
|
import { toSingleLast } from "@/prelude/array.js";
|
||||||
|
|
||||||
export function setupEndpointsAuth(router: Router): void {
|
export function setupEndpointsAuth(router: Router): void {
|
||||||
router.post("/v1/apps", async (ctx) => {
|
router.post("/v1/apps", async (ctx) => {
|
||||||
|
@ -29,7 +30,8 @@ export function setupEndpointsAuthRoot(router: Router): void {
|
||||||
const { client_id, state, redirect_uri } = ctx.request.query;
|
const { client_id, state, redirect_uri } = ctx.request.query;
|
||||||
let param = "mastodon=true";
|
let param = "mastodon=true";
|
||||||
if (state) param += `&state=${state}`;
|
if (state) param += `&state=${state}`;
|
||||||
if (redirect_uri) param += `&redirect_uri=${redirect_uri}`;
|
const final_redirect_uri = toSingleLast(redirect_uri);
|
||||||
|
if (final_redirect_uri) param += `&redirect_uri=${encodeURIComponent(final_redirect_uri)}`;
|
||||||
const client = client_id ? client_id : "";
|
const client = client_id ? client_id : "";
|
||||||
ctx.redirect(`${Buffer.from(client.toString(), "base64").toString()}?${param}`);
|
ctx.redirect(`${Buffer.from(client.toString(), "base64").toString()}?${param}`);
|
||||||
});
|
});
|
||||||
|
|
|
@ -106,15 +106,17 @@ export default defineComponent({
|
||||||
.split("&")
|
.split("&")
|
||||||
.reduce((result, query) => {
|
.reduce((result, query) => {
|
||||||
const [k, v] = query.split("=");
|
const [k, v] = query.split("=");
|
||||||
result[k] = decodeURI(v);
|
result[k] = decodeURIComponent(v);
|
||||||
return result;
|
return result;
|
||||||
}, {});
|
}, {});
|
||||||
const isMastodon = !!getUrlParams().mastodon;
|
const isMastodon = !!getUrlParams().mastodon;
|
||||||
if (this.session.app.callbackUrl && isMastodon) {
|
if (this.session.app.callbackUrl && isMastodon) {
|
||||||
const redirectUri = decodeURIComponent(getUrlParams().redirect_uri);
|
const redirectUri = getUrlParams().redirect_uri;
|
||||||
if (!this.session.app.callbackUrl.split('\n').some(p => p === redirectUri)){
|
if (!this.session.app.callbackUrl.split('\n').some(p => p === redirectUri)){
|
||||||
this.state = "fetch-session-error";
|
this.state = "fetch-session-error";
|
||||||
this.fetching = false;
|
this.fetching = false;
|
||||||
|
console.log(`redirect uri: ${redirectUri}`);
|
||||||
|
console.log(`reg_app uris: ${this.session.app.callbackUrl.split('\n').join(',')}`);
|
||||||
throw new Error("callback uri doesn't match registered app");
|
throw new Error("callback uri doesn't match registered app");
|
||||||
}
|
}
|
||||||
const callbackUrl = new URL(redirectUri)
|
const callbackUrl = new URL(redirectUri)
|
||||||
|
|
Loading…
Reference in a new issue